Why do we need design patterns
Why do we need design patterns like Factory, Abstract Factory and Singlet开发者_开发问答on?
Design Patterns provide easy to recognize and use OOP solutions to common problems. They're inherently easy to maintain, because many people are familiar with them. This is very similar to how google works. Everyone knows HOW to google, so when you get a query like "What is the purpose of design patterns", you can very quickly use this common interface to solve a problem.
Design Patterns also solve specific programming challenges regarding usability and maintainability. Pick up the Gang of Four book and have a look at it.
If a problem occurs over and over again, a solution to that problem has been used effectively. That solution is described as a pattern.
In some cases, for practicality. When you see a common recurring problem, you find a common, general solution to solve it. It happens in architecture, mechanics, usability, and human behavior, and programming makes no exception.
In some other cases, the pattern is also a way to deal with "inefficiencies" of the language, where "inefficiency" is very broad in its meaning, and not always in a bad term. For example, some patterns typically used in java are less important in a language where functions are first class objects. Some design patterns are meaningful only in some languages, and impossible in others: Crockford describes Javascript patterns that are kind of unique to this language to deal with the potential minefield-like nature of the language (which, I must point out, is a really cool language, once you understand it).
精彩评论