Php design patterns

前端 未结 4 1039
执念已碎
执念已碎 2021-01-31 23:53

Ok, i\'d like to firstly make you notice that i have looked for \"php mvc design patterns\" and so and i haven\'t really found what i was looking for; still now, writing my ques

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 00:35

    What are they?

    Design patterns are language-agnostic blueprint solutions for common problems. They are not downloadable code or readymade implementations, but a theoretical approach you can implement/translate into working solutions.

    Design Patterns also allow for easier communication between developers who know patterns, because when developer A says: this is a Factory, developer B will know what is meant.

    Where could i find a list about every design patterns on the web? Or at least the 5-10 most used design patterns?

    • GOF patterns with examples in various languages
    • Fowler's POEAA
    • StackOverflow has plenty results
    • Five common PHP design patterns
    • Five more PHP design patterns
    • Design Patterns in PHP (with examples)

    There is also a recommendable book called PHP Design Patterns (german only) for which you can download the code samples at http://www.phpdesignpatterns.de/auflage-2/#beispiele

    Do phpbb, wordpress or joomla (that i know pretty well) use a design pattern? If yes, then which?

    Probably, but listing each and every pattern an application uses is rather pointless. Some patterns are tiny, some are more complex. You dont use them to use them, but to solve problems.

    Let me stress that: you dont use them to use them. They are not some sort of status symbol. You dont want to amass them. You even don't have to implement them by the book. Use them where appropriate with every variation required to solve a concrete problem in your application.

    I googled MCV PHP and found about 3 italian articles and read about 5 of the first pages ranked and i didn't understand pretty much nothing. They were conflicting and seemed to me confusing. I did understand that it is usefull to separate business login, script and view (?) but i didn't got anything.

    MVC is not a GOF pattern. It is listed in POEAA but it's way older than that. The MVC you usually see on the web has nothing to do with the "classic" MVC because there is the internet between view and the other two.

    Basically, there is not much to know about MVC. It's very simple pattern. The idea is to split a UI into three distinct roles. The model is all your business logic. Your controller handles any requests from the view and delegates to the model. Your view displays the model. You should be able to replace the controller and views without having to touch your model.

    Are there simple examples about design patterns and how they are better then (normal) writing styles?

    Plenty. See the links above for some examples. If they are not clear enough, have a look around StackOverflow searching for their names.

提交回复
热议问题