views:

112

answers:

2

Why do we need design patterns like Factory, Abstract Factory and Singleton?

+5  A: 

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 at it.

Stefan Kendall
A: 

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).

Stefano Borini