├── interface.php
├── static.php
├── abstract.php
├── encapsulation.php
├── inheritance.php
├── polymorphism.php
├── OOP.txt
└── README.md
/interface.php:
--------------------------------------------------------------------------------
1 | mySchool();
11 | }
12 |
13 | public function mySchool(){
14 | echo "I'm a school teacher";
15 | }
16 | }
17 |
18 | $teacher = new Teacher();
--------------------------------------------------------------------------------
/static.php:
--------------------------------------------------------------------------------
1 | userId = $id;
10 | $this->userName = $name;
11 | }
12 |
13 | public function display(){
14 | echo "User Id is " . $this->userId . " and User name is " . $this->userName . " and Age is " . self::$age;
15 | }
16 |
17 | public static function profile(){
18 | echo self::$age;
19 | }
20 | }
21 |
22 | $user = new UserData("101", "Shahid Nawaz");
23 | // $user->display();
24 |
25 | UserData::profile();
26 |
--------------------------------------------------------------------------------
/abstract.php:
--------------------------------------------------------------------------------
1 | name . " is " . $this->age . " years old.";
9 | }
10 |
11 | abstract public function school();
12 | }
13 |
14 | class Boy extends Student{
15 |
16 | public function describe(){
17 | return parent::details() . " and I am a high school student.
";
18 | }
19 |
20 | public function school(){
21 | return "
I like to read story book";
22 | }
23 | }
24 |
25 | $boy = new Boy();
26 | $boy->name = "Shahid Nawaz";
27 | $boy->age = 26;
28 | $boy->describe();
29 | echo $boy->school();
--------------------------------------------------------------------------------
/encapsulation.php:
--------------------------------------------------------------------------------
1 | name = $user_name;
11 | $this->age = $user_age;
12 | }
13 |
14 | public function setSalary($amount){
15 | $this->salary = $amount;
16 | }
17 |
18 | public function getSalary(){
19 | if($this->salary > 0){
20 | echo "Name: " . $this->name . "
Age: " . $this->age . "
Salary: " . $this->salary;
21 | } else {
22 | echo "Insufficient Balance!";
23 | }
24 | }
25 | }
26 |
27 | $user = new User("Shahid Nawaz", 26);
28 | $user->setSalary(1500);
29 | $user->getSalary();
--------------------------------------------------------------------------------
/inheritance.php:
--------------------------------------------------------------------------------
1 | userId = $id;
9 | $this->userName = $name;
10 | }
11 |
12 | public function display(){
13 | echo "User Id is " . $this->userId . " and User name is " . $this->userName . "";
14 | }
15 | }
16 |
17 | class Admin extends UserData{
18 |
19 | public $label;
20 |
21 | public function display(){
22 | echo "User Id is " . $this->userId . " and User name is " . $this->userName . " and label is " . $this->label . "";
23 | }
24 | }
25 |
26 | $user = new Admin("101", "Shahid Nawaz");
27 | $user->label = 'Administrator';
28 | $user->display();
29 |
30 |
--------------------------------------------------------------------------------
/polymorphism.php:
--------------------------------------------------------------------------------
1 | userId = $id;
9 | $this->userName = $name;
10 | }
11 |
12 | public function display(){
13 | echo "User Id is " . $this->userId . " and User name is " . $this->userName . "";
14 | }
15 | }
16 |
17 | class Admin extends UserData{
18 |
19 | public $label;
20 |
21 | public function display(){
22 | echo "User Id is " . $this->userId . " and User name is " . $this->userName . " and label is " . $this->label . "";
23 | }
24 | }
25 |
26 | $user = new Admin("101", "Shahid Nawaz");
27 | $user->label = 'Administrator';
28 | $user->display();
29 |
30 |
--------------------------------------------------------------------------------
/OOP.txt:
--------------------------------------------------------------------------------
1 | ## Static
2 | => Static method can be called without creating object (ex. ClassName::methodName())
3 | => Static property can be used in same class (ex. self::$property)
4 |
5 | ## Modifiers
6 | 1. Public (Can be access in same class or out of class)
7 | 2. Private (Can be access only in same class)
8 | 3. Protected (Can be used in same class and inheritance or interface class)
9 |
10 | ## Inheritance
11 | => Parent child concept
12 | => Child class can be used parent class public and Protected data
13 | => Child class can't access parent class private data
14 |
15 | ## Polymorphism
16 | => Polymorphism means the ability to have many forms
17 | => Same name two methods can works different purpose
18 | => There are two types of Polymorphism:
19 | 1. Compile time (function overloading)
20 | 2. Run time (function overriding)
21 |
22 | ## Encapsulation
23 | => Hide data from user
24 | => GETTER and SETTER methods concept
25 | => Can be get data using method
26 | => Can be validate data in method
27 |
28 | ## Abstraction
29 | => Can't make Object
30 | => Can be used by 'extends'
31 | => Can be create method definition with or without method body
32 | => If we create abstract method, class must be abstract
33 |
34 | ## Interface
35 | => Can't make object
36 | => Can be used by 'implements'
37 | => Can be implements multiple interface class in same time
38 | => Only create method defination, no method body allowed
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Object Oriented Programming Example
2 |
3 | ## Static
4 | => Static method can be called without creating object (ex. ClassName::methodName())
5 | => Static property can be used in same class (ex. self::$property)
6 |
7 | ## Modifiers
8 | 1. Public (Can be access in same class or out of class)
9 | 2. Private (Can be access only in same class)
10 | 3. Protected (Can be used in same class and inheritance or interface class)
11 |
12 | ## Inheritance
13 | => Parent child concept
14 | => Child class can be used parent class public and Protected data
15 | => Child class can't access parent class private data
16 |
17 | ## Polymorphism
18 | => Polymorphism means the ability to have many forms
19 | => Same name two methods can works different purpose
20 | => There are two types of Polymorphism:
21 | 1. Compile time (function overloading)
22 | 2. Run time (function overriding)
23 |
24 | ## Encapsulation
25 | => Hide data from user
26 | => GETTER and SETTER methods concept
27 | => Can be get data using method
28 | => Can be validate data in method
29 |
30 | ## Abstraction
31 | => Can't make Object
32 | => Can be used by 'extends'
33 | => Can be create method definition with or without method body
34 | => If we create abstract method, class must be abstract
35 |
36 | ## Interface
37 | => Can't make object
38 | => Can be used by 'implements'
39 | => Can be implements multiple interface class in same time
40 | => Only create method defination, no method body allowed
41 |
42 |
--------------------------------------------------------------------------------