Design patterns of mainstream MVC framework and principles of software design compliance

Source: Internet
Author: User
Tags zend framework ruby on rails

The original address, will continue to update the Http://it.zuocheng.net/mvc-design-pattern-design-principle-summary process technology Blog

This article takes the mainstream MVC framework as an example, such as Java ssh, PHP symfony and Zend Framework, after simply analyzing their design principles, find the design patterns used in them, and appreciate their code implementations to see what software design principles the designers have followed. For this article, one for learning, two for summary. The content below may not be comprehensive or inaccurate, but will be constantly revised and perfected.

Frame mode MVC pattern
    • y = f (x)
    • View = Controller (Model, Request)
Active Record Mode
    • Yii Active Record
    • Ruby on Rails Active Record
ORM mode
    • PHP's Doctorine
    • Hibernate for Java
Three/Four layer architecture, 3/4-tier ARCHITECTURE
    • The MVC framework draws on the layered thinking of the three/four layer architecture, layering the entire system, most commonly in the Model layer.
    • SSH Dao/javabean, Service, Response, etc.
    • Symfony 2 of Doctrine, Service, view, etc.
Use of design Patterns Compound mode, Compound pattern
    • If the MVC framework does not use compound mode, this article has no meaning.
Singleton mode, Singleton pattern
    • Controller, context, View and other framework core classes use a singleton mode
Multi-case pattern, multition pattern
    • All kinds of resource pool, process pool, thread pool (behind PHP two not used)
Strategy mode, Strategy pattern proxy mode, proxy pattern
    • Use of abstract classes
Factory mode, Factory Methond pattern

Creation of the Action object

Abstract Factory mode, Factory pattern
    • Ajxaaction, Webaction, apiaction, and action for Ajax and web combinations, and action for Ajax and API combinations, complex frameworks use abstract factory patterns
Façade mode, facade pattern

Logger class, third party open source Logger class Package Unified interface, the third party Logger cumbersome interface shielding

Adapter Pattern
    • Zend Framework of the Zend_db_adapter class, the specific database (Mysql, Oracle, SQLite) class interface through the driver class package, to provide a unified interface for the upper layer
    • Zend_cache re-encapsulation of different Cache interfaces
Stencil mode, template Method pattern
    • Abstract classes of various complex logic
    • Extension classes for Frameworks
Builders mode, builder pattern
    • The adherence and practice of the dependency injection principle separates the construction of a complex object from its representation, allowing the same build process to create different representations.
    • The creator of the Content object is the Controller
    • The creation of the Config object
    • Object object creation of ORM
Bridge pattern, bridge pattern, command pattern
    • Http request parsing is the command mode
    • Console for Symfony 2
    • Command class for Symfony 2
Decoration mode, Decorator pattern
    • Action for Ajxaaction, Webaction, Apiaction, and Ajax and web combinations of actions or Ajax and API combinations
Iterator mode, Iterator pattern
    • Traversal of routing settings
Combination mode, COMPOSITE pattern Observer mode, Observer pattern
    • Various Trigger classes
    • Various types of custom extensions
Responsibility chain model, Chain of Responsibility pattern
    • Parsing of routes, especially restful URLs, targeting action classes and methods based on the routing table (Chain of responsibility)
Visitor mode, Visitor pattern mode, state patter prototype mode, Prototype pattern
    • Action, the execution is handed over to another action, such as redirect or Forward, and the action to get executed is consistent with the property, state, and context of the original action. Prototype mode is the better choice.
Mediator mode, mediator pattern
    • The class that acts as the mediator is the context, some framework context classes that abstract the request, Respose, GlobalConfig, and so on, and provide a unique way to call the business code, which is the interface provided by the Context class
Interpreter mode, interpreter pattern Hengyuan mode, Flyweight pattern
    • General State Class
    • Various Util classes
    • HTTP Meta class, special character Fu Yuan collation
Memo mode, Memento pattern
    • system logs, status, to support rollback
    • Database transactions
Software Design Principles SOLID Single duty principle (simple responsibility pinciple SRP) open-close principle (open-closed Principle, OCP) Richter substitution principle (Liskov Substitution PRINCIPLE,LSP) Dimitri (Law of Demeter LoD), least knowledge principle (Least knowledge PRINCIPLE,LKP) interface Isolation principle (Interface segregation Principle, ISP) dependency inversion principle ( Dependence inversion Principle)
    • The use of builders ' patterns
    • Use of routing tables, or various other configurations are collected in the configuration file, using a dependency injection container to implement decoupling of code and implementation

Design patterns of mainstream MVC framework and principles of software design compliance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.