本文介绍了PHP设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想首先让您注意到我一直在寻找"php mvc设计模式",因此我并没有真正找到我想要的东西.现在,在写我的问题时,我找不到我要问的任何相关且如此具体的问题.但是我知道我可能是错的,无论如何考虑这个问题和一个可能对突击队有用的问题包.

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.

问题

  1. 我想知道我们应该如何考虑设计模式.我的意思是:他们是什么?它们仅仅是二进制文件,可以帮助我们设计一致的应用程序吗?他们这么用吗?为什么?
  2. 在哪里可以找到有关网络上每个设计模式的列表?还是至少有5-10种最常用的设计模式?
  3. Phpbb,Wordpress或Joomla(我非常了解)是否使用设计模式?如果是,那是什么?
  4. 我用Google搜索了 MCV PHP ,发现了约3篇意大利语文章,并阅读了排名前5的第一页,但我对此一无所知.他们是矛盾的,在我看来似乎很混乱.我确实知道将业务登录名,脚本和视图(?)分开是很有用的,但是我什么也没有.我可能很愚蠢或有些愚蠢,但在哪里可以找到不错的官方(由Gang of Four或实际上知道他在说什么的人写的)mvc教程或与php相关的文档? /li>
  5. 是否有关于设计模式的简单示例,以及与(正常)书写风格相比有何改进?是否有关于MVC或其他设计模式的简单示例?例如,一个写有设计模式的简单博客?
  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 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?

提示

我更喜欢免费的解决方案.我不喜欢框架,因此即使(我知道)它们具有mvc和其他有效的设计模式和优点,也请不要引用它们.我还是不喜欢他们.谢谢

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

通知

明天以后,我将选择我接受的答案,所以,请抽出宝贵的时间来回答问题.

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

推荐答案

设计模式是针对常见问题的与语言无关的蓝图解决方案.它们不是可下载的代码或现成的实现,而是可以实现/转换为有效解决方案的理论方法.

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.

设计模式还可以使了解模式的开发人员之间更轻松地进行通信,因为当开发人员A说:这是工厂时,开发人员B就会知道这是什么意思.

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.

  • 带有各种语言示例的GOF模式
  • 福勒的POEAA
  • StackOverflow有很多结果
  • 五个常见的PHP设计模式
  • 还有五个PHP设计模式
  • PHP中的设计模式(带有示例)
    • 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)
    • 还有一本值得推荐的书,叫做《 PHP设计模式》(仅德语),您可以在 http://www.phpdesignpatterns.de/auflage-2/#beispiele

      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

      可能,但是列出应用程序使用的每种模式是毫无意义的.有些模式很小,有些则更复杂.您不使用它们来使用它们,而是要解决问题.

      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.

      MVC不是GOF模式.它已在POEAA中列出,但比它早得多.您通常在网络上看到的MVC与经典" MVC无关,因为视图和其他两个视图之间存在互联网.

      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.

      基本上,关于MVC的知识不多.这是非常简单的模式.这个想法是将一个UI分成三个不同的角色.该模型是您所有的业务逻辑.您的控制器处理视图中的所有请求并将其委托给模型.您的视图将显示模型.您应该能够更换控制器和视图,而无需接触模型.

      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.

      很多.有关示例,请参见上面的链接.如果不清楚,请查看StackOverflow以查找其名称.

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

      这篇关于PHP设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:04