Skip to content

Instantly share code, notes, and snippets.

@arodbits
Created February 23, 2017 21:18
Show Gist options
  • Save arodbits/e62ee761a162facacbb776899eed24fa to your computer and use it in GitHub Desktop.
Save arodbits/e62ee761a162facacbb776899eed24fa to your computer and use it in GitHub Desktop.
identifying OOP fundamental parts - SportsRecruits/OOP-workshop
<?php
/*
Research about:
- OOP PHP INHERITANCE
- OOP PHP INTERFACES
- Polymorphism
*/
//
//extends, implements (contract, protocol, ENFORCEMENT (ARMY))
interface AccountContract
{
public function setPost();
public function getPost();
}
class Account implements AccountContract //<--- is this correct?
{
public function setPost($post)
{
}
public function getPost()
{
}
}
class InstagramAccount implements AccountContract //<----- how about this?
{
public function setPost($post)
{
// INstagramAPI::post();
}
public function getPost()
{
//
}
}
class FacebookAccount
{
public function setPost($post)
{
// FacebookAPI::post();
}
public function getPost()
{
//
}
}
//Class used to identify all the main parts involved in OOP.
class Account
{
protected $amount = 0;
// private $a = 'i am a';
// public $b = 'foo';
public function __construct($amount)
{
$this->setDeposit($amount);
}
public function setDeposit($amount)
{
$this->amount += $amount;
}
public function getAmount()
{
return $this->convertToJapanCurrency($this->amount);
}
protected function convertToJapanCurrency($a)
{
return 'SERGARTERAW' . $a;
}
}
class User
{
public function deposit()
{
// (new Account)->b; //work
// (new Account)->a; //wont work
// (new Account)->amount; //= 100;
$account = (new Account(100));
$account->setDeposit(100);
$account->getAmount(); //200
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment