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.
Example:
<?php
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.
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.
Example:
<?php
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.
Please post more contents ...
ReplyDelete