Tuesday, July 14, 2009

PHP: Object Oriented Programming

Object oriented programming concepts were introduced in PHP1.4, I guess.
How many people around you play with object oriented programming?
If not working in any kind of MVC frameworks, I guess very short number of people.
Developers are often used to structured programming and don’t bother themselves learning object oriented programming concepts and paradigm.
Well, when software engineers realized that it’d become very difficult to manage and maintain thousand lines of code as well as impossible to represent real world object in computer world, object oriented programming was introduced. Since then dramatic improvements have been made to OOP.

In object oriented programming inheritance, polymorphism, encapsulation, dynamic binding and exception handling has great value, usage and advantages, however class and objects are the most basic concept.

Class is blue print containing properties and method associated with same entity. Object is the instance of the class and is used to access properties and method of the class.
In addition to OOP, design pattern make jobs easier for the programmers.
Singleton, factory and specially MVC design patterns are very useful these days.

In singleton design pattern one object of the class exist throughout the life cycle of the software application. If programmer tries to instantiate another object of the same class, a reference to the object instantiated earlier, is granted.

A class implementing factory design pattern works as bridge between multiple classes. Consider an example of using multiple database servers like SQL Server and Oracle. If you are developing an application using SQL Server database as backend, but in future need to change backend database to oracle, you will need to modify all your code, if you haven’t written your code following factory design pattern.
In factory design pattern you need to do very little work to achieve this. A class implementing factory design pattern takes care for you and lessen your burden. Switching from database server won’t bother you at all. You just need to make some small changes in your configuration file.

Revolution of MVC design patterns cause dramatic changes in software development life cycle. Prior to MVC, developers were mixing code all around. It was difficult to figure out where the business code resides and where presentation code is written. Intelligent software engineers, though, were trying hard to separate their business logic from presentation logic; this however wasn’t effective enough for new comers to understand their code and to do necessary maintenance. Without the help of the person behind the project, it’d taken more time to understand the directory structure used.
These draw backs were mostly addressed when MVC design patterns were introduced.

In MVC design pattern M stands for Model. Model contains your application’s business logic.
V stands for View. It’s the presentation layer.
While C stands for controller that work as glue between view and model. From glue I mean it takes data from view and give it to the model, model then process the data and produced desired results. The data, thus obtained, is given to the view. Controller can also be compared to event handlers. It responds to certain events such as posting the data back to server by clicking submitted data.
Hopefully I will unveil some other fact about OOP and design pattern later some time.


  1. my search for an article on php's oop ended here...thanks a lot

    PHP Programming

  2. Nice simple and useful information regarding PHP.

    Web design and development

  3. Boutique Logo Design
    I recently visited the linkage you share here and it's actually a wonderful place for web developer and web developer new bird like me. I find the site very enlightening and worth visiting. I also love the design and the layout it carries.

  4. Its a very nice article. I have share this article to all my friends. Thanks for share this information.

    1. This is really a nice post, that you have updated us with all of nice information that can be very useful for future aspect.

  5. The information shared was indeed very useful. Thanks for the share.

  6. but no confirm oops program and uses zend

  7. I really like how your class timings of your blog. I enjoyed reading your blog and it is both instructional and interesting. Website Development Bangalore | Web Design Company Bangalore India

  8. If you've never used an object-oriented programming language before, you'll need to learn a few basic concepts before you can begin writing any code. Web Design Bangalore

  9. BlueHost is definitely the best web-hosting company for any hosting plans you might need.

  10. It is an unprecedented sharing...I am especially happy with the substance you have said. I expected to thank you for this unimaginable article.
    PHP Development Company In Bangalore | Best Services Website Design