开发者

Php design patterns

开发者 https://www.devze.com 2023-01-28 14:31 出处:网络
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 question, i cannot find any

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 question, i cannot find any related and so specific question as i am going to ask. But i know i'm probably wrong, anyway consider this question and a question pack that could be usefull togheter.

Question

  1. I was wondering how we should consider the design patterns. I mean: What are they? Are they simply binaries that help us designing consistent application? Are they so used? Why?
  2. Where could i find a list about every design patterns on the web? Or at least the 5-10 most used design patterns?
  3. Do Phpbb, Wordpress or Joomla (that i know pretty well) use a design pattern? If yes, which?
  4. 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 else. I am probably stupid or something but where could i find a nice and official (means written by the Gang of Four or someone who actually know what开发者_JS百科 he is talking about) mvc tutorial or documentation related to php?
  5. Are there simple examples about design patterns and how they are better then (normal) writing styles? Are there simple examples about a mvc or other design pattern? For example a simple blog written with a design pattern?

Tips

I'd prefer free solution first. I don't like frameworks, so please don't refer to them even if (i know) they have mvc and other valid design patterns and benefits. I still don't like them. Thanks

Notice

I'll choose my accepted answer after tomorrow, so, please, take your time to answer.


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.


You would probably get better results googling for MVC PHP instead of MCV PHP. Design patterns can be applied to all object oriented languages so you might be best advised to look into THE design pattern book and into Object Oriented Programming with PHP.

There also is an article series on DZone about practical PHP patterns.


Here is a list of design pattern (not only for PHP): Wikipedia


I would also advise to take a look at php design patterns list. I hope you will find it useful.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号