Nurasto.com Website

My digital scrapbook

Anti-Pattern Mambo Jambo with PHP Class

on under Uncategorized • Be the first to comment

Anti-Pattern is an alias for software component who do the project without Design Pattern. PHP feature able to implement design pattern but sometimes design pattern make us really sweat especially for simple site. Model View Controller also implement few Design Pattern and you will accidently realize this is huge and amazing yet confusing.

Steping into Object Oriented Software Engineering is not an easy task, I admit it but when we spare our time to learn the fundamental of Object Oriented it would worth for our coding's life. The basic fundamental of Object Oriented in PHP are Inheritance, Encapsulation, and Polymorphism. Let's talk about these matter.

Inheritance

We could inherit class, like we have our dad's and mom's blood. The parent class called as Super Class, and the child class called as Sub Class. In PHP 4 this inheritance already exist but we can't have two super class like previous example. PHP 5 does have same rules but we could add interface to our code by implements keyword. The inheritance keyword in PHP is extends.

Encapsulation

Actually, we must comply this one in every OOP language. The encapsulation allows us to decide the visibility of attributes and methods. In PHP 4 we call attribute as var and methods are functions but the visibility is ignored. PHP 5 have visibility in class such as public, protected, and private. PHP 5 didn't have strong data-typed to allow us defined what data type could be accepted by attribute, I heard that PHP 6 will implement this feature as part of the language.

Polymorphism