Wednesday, 13 February 2013

Design Pattern in PHP

Design PatternThe design pattern is an architecture to make the project robust and fast. In design pattern, the structure of the programmer is be in such a way by which we can make the code reusable, objects reusable, and the make the code simplest and optimized.

Design pattern is basically five types:

Singleton Pattern: This pattern has the concept of making a single object of any class in whole of the project and we use that single object instance anywhere.
                  The basic concept behind it is the create a single instance of a class and this object is accessible at any where in the project.


    class test() {
      public static $instance = null;
       public static function getInstance(){
          if(NULL == self::$instance){
               self::$instance = new test();
           return self::$instance;

Factory Pattern: This pattern is used in business logic side. We will have those function and functionality which we can use multiple times in the project.
             It means we have such function in the Factory that have the common functionality and will be reusable. This pattern basically used to reduce the code and make the code quick changeable.

Example: if we want to make a calculator or like such any functionality then we will create a class and different methods in which we will pass only parameters and the corresponding functionality will perform. and we can use this class in other projects also.

Other Patterns are: 

Abstract Patterns.
Decorator Pattern: The decorator pattern is a structural design pattern which enables us to add new or additional behavior to an object during run time, depending on the situation.   
Strategy Design Pattern.

1 comment: