Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Model-View-Controller (MVC)

The Model-View-Controller architectural pattern provides a widely used solution to separate the user
interface from the logic of an application. The user interface of the application (view) interacts with the
data (model) using the controller, which contains the business rules needed to manipulate data sent to
and from the model.
To put this into an e-commerce perspective, consider a customer adding a product to their shopping
basket clicks on an Add to basket button within the view/user interface. The controller processes this
request and interacts with the model (basket) to add the product to the basket. Similarly, the data from
within the basket is relayed back to the user interface through the controller, to display how many
products are in the basket, and the value of the contents.
Because we are creating a framework for use with websites and web applications, we can further extend the
representation of the MVC pattern to reflect implementation in such a framework. As discussed earlier, the
models represent data; this is primarily stored within the database. However, in our framework we will have
a series of models, which take the data and store it within themselves in a more suitable format, or allowing
the data to be manipulated more easily. So, we could in fact add our database to this diagram, to show the
interaction with the models and the database. We are also viewing the end result of our website or web
application in a web browser, which renders the views, and relays our interactions (for example mouse clicks
or field submissions), back to the controller.
Registry Pattern
A registry object basically acts as a container for objects that you want to be universally accessible
throughout your project, while avoiding the use of . . . gulp . . . global variables! You'll find that its
implementation is fairly simple, but extremely powerful and convenient.
The registry pattern provides a means to store a collection of objects within our framework. The need
for a registry arises from the abstraction provided with the MVC pattern. Each set of controllers and
models we create (for example products, shopping basket, page viewing, or content management) need
to perform some shared tasks, including:
Querying the database
Checking if the user is logged in, and if so, getting certain user data
Sending data to the views to be generated (template management)
Sending e-mails, for instance to confirm a purchase with the customer
Interacting with the server's file system, for instance to upload photographs of products

class Registry {
protected $_objects = array();

function set($name, &$object) {
$this->_objects[$name] =& $object;
}

function &get($name) {
return $this->_objects[$name]; }

}
Singleton pattern- is a design solution where an application wants to have one instance of the class.
We can access the singleton instance globally.

You might also like