Created
July 13, 2021 11:23
-
-
Save orhanerday/adbc8fdddea55c7e8fb83c8879d2a9ad to your computer and use it in GitHub Desktop.
Simple oop project for php 7.4.9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Account | |
{ | |
//Properties | |
private int $id; | |
private string $name; | |
private float $balance; | |
/** | |
* Create a new account instance. | |
* | |
* @return void | |
*/ | |
public function __construct($id, $name, $balance) | |
{ | |
$this->id = $id; | |
$this->name = $name; | |
$this->balance = $balance; | |
} | |
/** | |
* @return integer | |
*/ | |
public function getId(): int | |
{ | |
return $this->id; | |
} | |
/** | |
* @return string | |
*/ | |
public function getName(): string | |
{ | |
return $this->name; | |
} | |
/** | |
* @return float | |
*/ | |
public function getBalance(): float | |
{ | |
return $this->balance; | |
} | |
public function getAll() | |
{ | |
echo "Id : $this->id <br>Name : $this->name <br> Balance : $this->balance"; | |
} | |
} | |
class SpecialAccount extends Account | |
{ | |
private float $interest; | |
public function __construct($id, $name, $balance, $interest) | |
{ | |
parent::__construct($id, $name, $balance); | |
$this->interest = $interest; | |
} | |
/** | |
* @return float | |
*/ | |
public function getInterest(): float | |
{ | |
return $this->interest; | |
} | |
/** | |
* @override | |
*/ | |
public function getAll() | |
{ | |
parent::getAll(); | |
echo "<br> Interest : $this->interest"; | |
} | |
} | |
class Controller | |
{ | |
public function index() | |
{ | |
$account = new Account(1, "orhan", 123.32); | |
print $account->getId() . PHP_EOL; | |
print $account->getName() . PHP_EOL; | |
print $account->getBalance() . PHP_EOL; | |
print $account->getAll() . PHP_EOL; | |
print "<br><br><br>"; | |
$special_account = new SpecialAccount(2, "Hasan", 32.00, 1500.00); | |
print $special_account->getId() . PHP_EOL; | |
print $special_account->getName() . PHP_EOL; | |
print $special_account->getBalance() . PHP_EOL; | |
print $special_account->getInterest() . PHP_EOL; | |
print $special_account->getAll() . PHP_EOL; | |
} | |
} | |
(new Controller)->index(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment