This article I will discuss the basic object oriented programming in PHP, including encapsulation and inheritance and polymorphism. Encapsulation is the concept to hide information from the user which consists of methods and properties. While inheritance is the concept of the use of data members and methods on the default class. Besides discussing complementary components in object-oriented programming.
The basic concepts of object oriented programming in PHP
Before going any further, we need to understand about the definition of the object. In principle, the object is an element that can be understood. If the real viewpoint, the object is something that has a shape and mass, but if we are talking concept, object is an idea / ideas.
Examples of the object is a person, animal, car, idea. In conclusion every object has something that can be distinguished from one object to another object, where each object in general have remained condition / state and operation / method. Or, simply, object identifier / properties / attributes and functions.
For example, a car has identifier or attribute that is, have the tire, wheel, doors, engine, etc. Functions / its behavior is can be a condition of the car which can be accelerated or slowed down, can sound the horn, can turn on the lights. From this concept then developed a new programming technique that is based on the real world / real object
2. Object Oriented Programming in PHP
From the description above can be concluded that the simple, object-oriented programming means a programming technique in the development process using the terminology of objects, where each object has attributes and functions that can interact with each other as well as objects.
The characteristics that is the basic idea of how to develop a complex software using the object model. Thus the software development process will be easier because it will adjust to the object programming model with which we will create
Additionally PBO has a goal to provide insight to the user or client systems. This is because the user / client can more easily understand the flow of programming faced.
3. Main pillar Object-oriented Programming in PHP
I think the PBO has three main pillars
Encapsulation is a technique used to perform concealment of information that is not required by the user. Hidden data in the form of attributes and functions that are interconnected to form a set of data structures. By using this method of how a programmer who uses a new data type from other developers do not need to understand how the data type is created, but quite understand about the interface of the class
Inheritance presented modeling derived from the real world, where each new data types can be derived from the data type of the parent or superclass so that the derived class will inherit all the properties of its parent. But it is worth noting that the derivative is not just easy to access data and functions of the parent class, but the concept of the object itself. If the “cat” is a derivative of “mammals”, it means “cat” not only has all the data and functions of the “mammal”, but “cat” itself is a “mammal”
Model or form that can be used on a variety of objects. Different objects derived from the same parent and can have the same function with different implementation. For example, we have a parent class that has the function of a “show”, then lowered to 2 different other classes. At the time of the first component is displayed with the function of the “show”, it will be routine work of the first component as well as the second component. So even though both are met by the same parent component to perform the same function, but in practice, the function of the “show” will perform a routine in accordance with the respective derivative components.
Discussion on the concept and implementation of object oriented programming in PHP, i will present in my next article
Latest posts by Sigit Prasetya Nugroho (see all)
- How To Create PDF Receipt Note using FPDF Library - August 10, 2017
- PHP Tutorial How To Use Google API To Access Google Plus Service - August 7, 2017
- How To Upload Image Using PHP, AdminLTE Framework And JQuery Plugin For Beginner - August 4, 2017