LECTURE - 3
• Design and architectural patterns in PHP, including:
1. Model-View-Controller
2. Registry
3. Singleton
• There are a few patterns of particular interest to us, as we are looking to develop a framework:
• Model-View-Controller (MVC)
• Registry
• Singleton
• Model–view–controller (MVC) is a software architectural patterns for implementing user interfaces on computers.
• It divides a given application into three interconnected parts
• 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.
• Screen of any application
• Chek box,scroll etc
• To use this we operate the software
• Logic behind the view is called controller
• It is also called mechanism
• Data which we store
• Whether in file or data base
When click on any menu there is a mechanism behind it which is stored in controller data is accessed by controller for example update delete insert etc view and model is not directly accessed interaction may be different between 3 components not in diagram above
• The model is the central component of the pattern. It expresses the application's behavior in terms of the problem domain, independent of the user interface. It directly manages the data, logic and rules of the application.
• The HTML is the "skeleton" of bedrock content. Text that communicates information to the reader.
• A view can be any output representation of information, such as a chart or a diagram. Multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants.
• The CSS adds visual style to the content. It is the "skin" that we use to flesh out our skeleton and give it a particular look. We can swap in different skins via CSS without altering the original content in any way. They are relatively, but not completely, independent
• The third part, the controller, accepts input and converts it to commands for the model or view.
• The browser is responsible for combining and rendering the CSS and HTML into a set of final, manipulatible pixels on the screen. It gathers input from the user and marshals it to any JavaScript code necessary for the page to function.
• User run car with staring
• User run car by Escalator which is actually is a view
• Bit your action is go to engine which is controller
• When you press escalator then flow of petrol is raised which is handle by model/storage
• So software is also work in this way
• A controller has more than one view
• For example software has multiple views
• Text
• Image
• Video
• Animation
• User controls
• Control structures (if ,loop)
• Interfaces (function)
• Components
• This mechanism is developed by programmer
• File system
• Relational database
• Object oriented data base
• Data base is design and manage by DBA
User interface Logic/Flow Storage
(View)
Designer
(controller)
Programmer
(model)
DBA
• 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.
• the models represent data; this is primarily stored within 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
Technologies
• AWT/Swing ----- Java Packages
• Silver lite --- .NET
• HTML+CSS
• Flash
• Visual force
Technologies
VB.NET,C#.net
PHP
Python
Technologies
Oracle
SQL Server
Mysql
Model(DBA)
• The registry pattern provides a means to store a collection of objects within our framework
• A Well known object that other object can use to find common object and services
• A registry is essentially a global object registries are implemented as singleton
• Registry are implemented some kind of map either Hash map or other customer registry Registry
Id
(Key)
1
Value
Customer object (ali)
2 Customer object (asad) get Customer[intCustomerID]
Add customer[id.Customerobj]
• Most systems and frameworks abstract functions into objects of their own,
• In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object.
• This is useful when exactly one object is needed to coordinate actions across the system.
• Ensure a class has only one instance, and provide a global point of access to it.
• Make the class of the single instance object responsible for creation, initialization, access, and enforcement. Declare the instance as a private static data member. Provide a public static member function that encapsulates all initialization code, and provides access to the instance.
• The Singleton pattern is used to design the classes which provides the configuration settings for an application. By implementing configuration classes as Singleton not only that we provide a global access point, but we also keep the instance we use as a cache object.
• Next important stage in the design of our framework is its structure.
• We need the structure to provide for:
1. Models
2. Views (We may wish to integrate the ability to switch styles for the websites we power with our framework, so one folder for each unique set of templates, styles, and views would be a good idea.)
3. Controllers (We may wish to have each controller within its own folder, as we may have accompanying functions in additional files, so we can keep them organized.)
4. Administration controllers (If we are to add administration tools to our framework, we should provide some administration controllers. These would be controllers for the various models we have; however, they would be designed for administrative tasks, and would be accessible only to administrators.)
5. Registry
6. Registry objects
7. User/administrator uploaded files
8. Third-party libraries
9. Any other code
• Number of different ways to implement the patterns we discussed
Let start
MVC
• we wish to implement the main features that the sites powered by our framework will use. But in start we have only structure so we work on example or model to define working.
• we needs to have a method to create certain objects and store them with a key; it needs another method which when passed with a key as a parameter, returns the object in question.
• Settings
• The registry is our primary store for both settings and commonly used objects, so we need to make provision for settings management.
• Registry objects