Design Pattern In php

Use the Repository Design pattern to refactor app's controller

First , we create a RepositoryInterface as a contract that defines the methods a class MUST have defined.

ReflectionClass and IoC demonstration

PHP 5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions, methods and extensions. Additionally, the reflection API offers ways to retrieve doc comments for functions, classes and methods.

The ReflectionClass class reports information about a class:

Repository Pattern

A repository represents an architectural layer that handles communication between the application and data source. It is a widely used pattern whose main point is that the application does not have to know which data source is implemented and how it is implemented. This makes it easier to switch to another data source or implement structural changes to the existing data source.


Real world example: There can only be one president of a country at a time. The same president has to be brought to action, whenever duty calls. President here is singleton.
Purpose: To have only one instance of this object in the application that will handle all calls.

Key: To create a singleton, make the constructor private, disable cloning, disable extension and create a static variable to house the instance

Subscribe to RSS - Design Pattern In php