PHP OOP
PHP - What is OOP
From PHP5, you can also write PHP code in an object-oriented style.Object-Oriented programming is faster and easier to execute.
OOP stands for Object-Oriented Programming. Procedural programming is about writing procedures or functions that perform operations on the data, while object-oriented programming is about creating objects that contain both data and functions.
Object-oriented programming has several advantages over procedural programming:
- OOP is faster and easier to execute
- OOP provides a clear structure for the programs
- OOP helps to keep the PHP code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug
- OOP provides a clear structure for the programs
The "Don't Repeat Yourself" (DRY) principle is about reducing the repetition of code. You should extract out the codes that are common for the application, and place them at a single place and reuse them instead of repeating it.
PHP - What are Classes and Objects?
Classes and objects are the two main aspects of object-oriented programming.
So, a class is a template for objects, and an object is an instance of a class. When the individual objects are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties.
`Object Oriented Concepts
Classes and objects are the two main aspects of object-oriented programming.
Before we go in detail, lets define important terms related to Object Oriented Programming
- Class − This is a programmer-defined data type, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.
- Object − An individual instance of the data structure defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.
- Member Variable − These are the variables defined inside a class. This data will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.
- Member function − These are the function defined inside a class and are used to access object data.
- Inheritance − When a class is defined by inheriting existing function of a parent class then it is called inheritance. Here child class will inherit all or few member functions and variables of a parent class.
- Parent class − A class that is inherited from by another class. This is also called a base class or super class.
- Child Class − A class that inherits from another class. This is also called a subclass or derived class.
- Polymorphism − This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it take different number of arguments and can do different task.
- Overloading − a type of polymorphism in which some or all of operators have different implementations depending on the types of their arguments. Similarly functions can also be overloaded with different implementation.
- Encapsulation − refers to a concept where we encapsulate all the data and member functions together to form an object.
- Data Abstraction − Any representation of data in which the implementation details are hidden (abstracted).
- Constructor − refers to a special type of function which will be called automatically whenever there is an object formation from a class.
- Destructor − refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.
What is OOPs?
Object Oriented is an approach to software development that models application around real world objects such as employees, cars, bank accounts, etc. A class defines the properties and methods of a real world object. An object is an occurrence of a class.
The three basic components of object orientation are;
- Object oriented analysis – functionality of the system
- Object oriented designing – architecture of the system
- Object oriented programming – implementation of the application
What is UML?
Unified Modeling Language UML is a technique used to design and document object oriented systems. UML produces a number of documents, but we will look at the class diagram which is very important to object oriented php programming.
`