Questions tagged [design-patterns]

A design pattern is a general reusable solution to a commonly occurring problem in software design.

In software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Design patterns are formalized practices a programmer can use to solve common problems when designing an application or system.

4450 questions
77
votes
10 answers

Non-OOP Design Patterns?

I have only heard the term "design pattern" being used for object oriented code, and the GoF patterns include only OOP design patterns, but design patterns are elegant solutions for commonly occuring programming problems, right? There is nothing in…
Anto
  • 11,187
  • 13
  • 68
  • 103
77
votes
5 answers

What is the "Fix Everything" design pattern?

In this 2003 article by Stephen Figgins on linuxdevcenter.com, Bram Cohen's BitTorrent is described as using the "Fix Everything" design pattern. A less common approach that both makes BitTorrent harder to grasp, but worthy of study, is Cohen's…
Aaron Hall
  • 5,945
57
votes
15 answers

When should I use—and not use—design patterns?

In a previous question of mine on Stack Overflow, FredOverflow mentioned in the comments: Note that patterns do not magically improve the quality of your code. and Any measure of quality you can imagine. Patterns are not a panacea. I once wrote…
ashmish2
  • 301
48
votes
6 answers

Is "Mapper" a valid design pattern or is it a variation of the "Factory" pattern?

A common pattern I see is what's known as the Mapper pattern (not to be confused with DataMapper which is something else entirely), which takes as an argument some kind of "raw" data source (e.g. an ADO.NET DataReader or DataSet) and maps the fields…
Wayne Molina
  • 15,684
47
votes
7 answers

When would polling for events be better than using observer pattern?

Are there scenarios where polling for events would be better than using the observer pattern? I have a fear of using polling and would only start using it if someone gave me a good scenario. All I can think of is how the observer pattern is better…
JoJo
  • 1,495
  • 2
  • 14
  • 21
45
votes
7 answers

Why is the factory method design pattern more useful than having classes and calling them individually?

From the "Gang of Four" design patterns, there's the Factory method: class Factory(product) case product when a new A when b new B when c new C end new Factory(a) Why is this more useful than having three classes, a, b, and c…
alt
  • 561
45
votes
13 answers

Design patterns - do you use them?

Being an IT student, I was recently given some overview about design patterns by one of our teachers. I understood what they are for, but some aspects still keep bugging me. Are they really used by the majority of programmers? Speaking of…
seth
  • 895
44
votes
4 answers

Why was dependency injection pattern not included in the Gang of four?

Why was the dependency injection pattern not incluided in the gang of four? Did GOF pre-date widespread automated testing? Is dependency injection now considered a core pattern?
Tom Squires
  • 17,755
  • 11
  • 67
  • 88
43
votes
3 answers

What are the drawbacks to the ActiveRecord pattern?

I'm curious what are the drawbacks to using the ActiveRecord pattern for data access/business objects. The only one I can think of off the top of my head is that it violates the Single Responsibility Principle, but the AR pattern is common enough…
Wayne Molina
  • 15,684
40
votes
4 answers

Mediator vs Observer?

Can someone provide me with a canonical answer on the differences between an Observer and a Mediator, and a summary of when you should use one pattern over the other? I am unsure of what kind of situation would require an Observer and what kind…
Rachel
  • 24,029
39
votes
2 answers

Difference between the Adapter pattern and the Proxy pattern?

As far as I understand, the adapter pattern is creating a wrapper object for our real object of interest, simply one more level of indirection, which provides flexibility. The flexibility is in that if the real object's interface is changed, then we…
Vorac
  • 7,129
36
votes
8 answers

How did separation of code and data become a practice?

Please read the question carefully: it asks how, not why. I recently came across this answer, which suggests using a database to store immutable data: It sounds like many of the magic numbers you describe - particularly if they are part dependent -…
Phil Frost
  • 1,569
32
votes
2 answers

Design Pattern for Data Validation

What would be the best design pattern for this problem: I have an Object A. Object A can either be registered or deleted from the database depending on the user request. Data validation is performed before registration or deletion of the object.…
melodui
  • 323
30
votes
10 answers

To design pattern, or not to design pattern

Design patterns are good, but complex. Should we use them in small projects? Implementing design patterns needs more sophisticated developers, which in turn raises project costs. On the other hand, they make code neat and clean. Are they necessary…
Saeed Neamati
  • 18,210
27
votes
3 answers

Understanding the bridge design pattern

I do not understand the "bridge" design pattern at all. I have gone through various web sites, but they haven't helped. Can anybody help me in understanding this?
user900721
1
2 3
13 14