Skip to content

Design Pattern

IT Notes → PHP @ December 22, 2020

  • Design patterns are just guidelines on how code should be designed for scenarios. It can be procedurally coded or using more favourably using OOPs.
  • Singleton Pattern gives access to a single resource not replicated. Here we have private constructor and a static function which creates a resource if and only if no resource exists. it returns the created or existing resource which is stored as a static property. An example here is MySQL connection link resource.
  • Factory Pattern creates a factory or generic class which returns instances or objects of separate specialised classes that handles same task separately. Here depending on say function parameter different objects are instantiated and returned. Consider data storage manager which instantiates storage classes depending on say user’s preference. So, he can choose between say INI or DB or XML which are implemented using an interface.
  • Registry Pattern creates a pattern where you can register resources and later on check if a resource is registered and retrieve it. Here we add all registered resources to a static property array and check against and retrieves from the array as required. We add say and class and its object as an associative array property.
  • MVC or Model-View-Controller is a design pattern where the controller is called by user (even in default action) and it interfaces with model (business logic) to change its state and finally view is called which reflects changes in model.
  • Active Record Pattern is a pattern where the data source is encapsulated so that the act of accessing the components is hidden within the class that implements the pattern. An example is we don’t worry about how SQL implements data row writing or fetching.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x