Home >Backend Development >PHP Tutorial >What is PHP design pattern and how to understand it_PHP tutorial
Friends who are doing program development should have heard of the word design pattern. For those who are doing Java development, they should hear this. You can understand what the word means, but for friends who do PHP, they often become more confused as they read it. So what exactly is a design pattern? In fact, the author doesn't understand either. Here are some explanations about design patterns extracted from the Internet. I hope I can gain some understanding.
When you are constantly trying to discover new features from your applications, do you find that the solutions you propose are so similar to some things you have implemented before? If you're a programmer (even if you've only been starting out for a short time), you probably answered "yes." It looks like you are using some old code to solve newly discovered problems during software development. You may have realized that your solution is a fundamental principle, a method that can be widely repeated not only by you but by all professional developers.
In fact, many programming problems are encountered repeatedly, and many basic methods (or design patterns) used to solve these problems have emerged. A design pattern is a template that teaches you how to organize your code using authentic and reliable designs.
History of Design Patterns
The term "design pattern" was originally coined in the field of architecture. In his 1977 book "A Pattern Language: Towns/Building/Construction", Christopher Alexander describes some common architectural design problems and explains how to use this collection of existing, well-known patterns to start new and effective designs. . Alexander's perspective has been well translated into software development, and he has long used existing components to construct new solutions.
All design patterns have some common characteristics: a name, a problem statement, and a solution.
1. The identification of a design pattern is important because it allows other programmers to immediately understand the purpose of your code without having to study too deeply (at least through this identification programmers will be familiar with this pattern) .
2. The problem description is used to illustrate the application field of this model.
3. The solution describes the execution of this model. A good discussion of a design pattern should cover the advantages and disadvantages of using the model.
A pattern is an effective way to solve a specific problem. A design pattern is not a library (a library of code that can be included and used directly in your project) but a template for organizing your code. In fact, there are many differences in the application of a code base and a design pattern.
For example, a shirt you buy from a store is a code library. Its color, style and size are determined by the designer and manufacturer, but it meets your needs. However, if nothing in the store suits you, then you can create your own shirt (design its shape, choose the fabric, and have it sewn together). But if you are not a tailor, you may find it easy to find a suitable pattern and then design your own shirt according to this pattern. Using a mockup, you can get a proficiently designed shirt in less time.
Back to discussing software, a data extraction layer or a CMS (content management system) is a library. It has been designed and coded before. If it can accurately meet your needs, then it is a library. Good choice.
One final thought: Just like a tailoring model, a design is of little use on its own. After all, you can't wear a model of clothing that's just pieced together from thin sheets of paper. Similarly, a software design model is just a guide. It must be specially designed according to the characteristics and requirements of the programming language and your application.
Another website about PHP design patterns is phpPatterns, URL: http://www.phppatterns.com