Object Oriented Programming
Object Oriented Programming
Design Patterns.
STRUCTURE OR SEQUENTIAL PROGRAMMING
class Employee {
// class body
}
SCOPE
Function Scope
Class Scope
Instance scope
GLOBAL SCOPE
}
ABSTRACT CLASSES
An abstract class cannot be instantiated. Instead it
defines (and, optionally, partially implements)
the interface for any class that might extend it.
You define an abstract class with the abstract keyword.
Let us try our abstract class
Abstract class Employee{
}
}
FINAL
//Now you can try something different, that works for you
Class AssociateTeamLead extends Developer {
}
FINAL FUNCTION
Abstract Class Employee implements Rules,
CodingStandards{
Final function set_salary($amount){
}
}
Every employee has salary, what is so special to implement with every user type.
We will be get into trouble If we try something like below
Class Developer extends Employee{
Function set_salary($amount){
}
}
INSTANCE / OBJECT
If a class is a template for generating objects, it follows
that an object is data that has been structured
according to the template defined in a class. An object is
said to be an instance of its class. It is of the
type defined by the class.
If will not be able to create instance for class Employee
as it is of abstract. So we will try to create instance for
class Developer.
$fazl = new Developer();
Let us get into more detail of class Developer, So that
we can explore more
OBJECT INSTANCE – EXAMPLE
Class Developer extends Employee{
Public $name;
Protected $salary;
Protected $department;
Private $tasks;
Function Developer($name=NULL){
If($name!=NULL) $this->name = $name;
}
Implement parent abstract method so that we can create instance for
this class
Function get_tasks(){
}
Function set_tasks(){
}
}
INSTANCE MEMBER VISIBILITY
Echo $asadk->get_department();
By changing the name for ‘$junaidA’, it also has changed the name for ‘$tlJunaid’.
That means that we have two handler for one instance. These two variables have the
reference of same instance.
CLONE
You might want to copy the reference of an object
and may want not to share the instance between
two variables. So instead of
$junaidA=$tlJunaid;
Try This
$junaidA= clone $tlJunaid;
$junaidA->name = ‘Junaid Ali’;
Echo $junaidA;
Echo $tlJunaid;
CLONE CONTINUES
Developer Object( [name] => Junaid Ali Developer Object( [name] => Junaid A.
[salary:protected] => [salary:protected] =>
[department:protected] => [department:protected] =>
[tasks:Developer:private] => [tasks:Developer:private] =>
[quota:protected] => [timimgs:protected] [quota:protected] => [timimgs:protected]
=> [client:protected] => ) => [client:protected] => )