Questions tagged [design-patterns]

A design pattern is a general reusable solution to a commonly occurring problem in software design. Use this tag for questions when you're having problems with the implementation of design-patterns. Please don't use this tag on questions about text pattern matching. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.

A design pattern is not a finished design that can be transformed directly into code. It is a description or template for solving a problem that can be used in many different situations.

Object-oriented design patterns typically show relationships and interactions between classes or objects without specifying the final application classes or objects involved. Many patterns imply object-orientation or a more generally mutable state, which may not be as applicable in functional programming languages, in which data is immutable or treated.

Design patterns are generally described using the Unified Markup Language ([tag: UML]) - a class diagram shows the relationship between the design pattern components. In addition, UML has a sufficiently extensive and expressive vocabulary that helps describe the details of patterns.

The seminal book that introduced the concept had four authors, often referred to as the "Gang of Four".

Gang of Four design patterns

Concurrency patterns

Other patterns

Useful links

Books

31951 questions
3589
votes
39 answers

What is dependency injection?

There have been several questions already posted with specific questions about dependency injection, such as when to use it and what frameworks are there for it. However, What is dependency injection and when/why should or shouldn't it be used?
AR.
  • 39,615
  • 9
  • 44
  • 52
2351
votes
24 answers

What are MVP and MVC and what is the difference?

When looking beyond the RAD (drag-drop and configure) way of building user interfaces that many tools encourage you are likely to come across three design patterns called Model-View-Controller, Model-View-Presenter and Model-View-ViewModel. My…
2296
votes
39 answers

What is Inversion of Control?

Inversion of Control (IoC) can be quite confusing when it is first encountered. What is it? Which problem does it solve? When is it appropriate to use and when not?
2166
votes
36 answers

What are drawbacks or disadvantages of singleton pattern?

The singleton pattern is a fully paid up member of the GoF's patterns book, but it lately seems rather orphaned by the developer world. I still use quite a lot of singletons, especially for factory classes, and while you have to be a bit careful…
Ewan Makepeace
  • 5,376
  • 9
  • 31
  • 31
2036
votes
42 answers

Difference between static class and singleton pattern?

What real (i.e. practical) difference exists between a static class and a singleton pattern? Both can be invoked without instantiation, both provide only one "Instance" and neither of them is thread-safe. Is there any other difference?
Jorge Córdoba
  • 51,063
  • 11
  • 80
  • 130
1464
votes
12 answers

Naming Classes - How to avoid calling everything a "Manager"?

A long time ago I have read an article (I believe a blog entry) which put me on the "right" track on naming objects: Be very very scrupulous about naming things in your program. For example if my application was (as a typical business app) handling…
froh42
  • 5,190
  • 6
  • 30
  • 42
1431
votes
24 answers

What is the difference between MVC and MVVM?

Is there a difference between the standard "Model View Controller" pattern and Microsoft's Model/View/ViewModel pattern?
Bjorn Reppen
  • 22,007
  • 9
  • 64
  • 88
1144
votes
29 answers

Does functional programming replace GoF design patterns?

Since I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative languages. One article I found makes a fairly strong…
Juliet
  • 80,494
  • 45
  • 196
  • 228
890
votes
24 answers

C++ Singleton design pattern

Recently I've bumped into a realization/implementation of the Singleton design pattern for C++. It has looked like this (I have adopted it from the real-life example): // a lot of methods are omitted here class Singleton { public: static…
Artem Barger
  • 40,769
  • 9
  • 59
  • 81
850
votes
29 answers

What is an efficient way to implement a singleton pattern in Java?

What is an efficient way to implement a singleton design pattern in Java?
Riyaz Mohammed Ibrahim
  • 9,505
  • 5
  • 26
  • 33
822
votes
27 answers

What is the difference between Builder Design pattern and Factory Design pattern?

What is the difference between the Builder design pattern and the Factory design pattern? Which one is more advantageous and why ? How do I represent my findings as a graph if I want to test and compare/contrast these patterns ?
Penguen
  • 16,836
  • 42
  • 130
  • 205
684
votes
20 answers

Why is __init__() always called after __new__()?

I'm just trying to streamline one of my classes and have introduced some functionality in the same style as the flyweight design pattern. However, I'm a bit confused as to why __init__ is always called after __new__. I wasn't expecting this. Can…
Dan
  • 33,953
  • 24
  • 61
  • 87
672
votes
7 answers

Examples of GoF Design Patterns in Java's core libraries

I am learning GoF Java Design Patterns and I want to see some real life examples of them. What are some good examples of these Design Patterns in Java's core libraries?
unj2
  • 52,135
  • 87
  • 247
  • 375
604
votes
21 answers

What are the differences between Abstract Factory and Factory design patterns?

I know there are many posts out there about the differences between these two patterns, but there are a few things that I cannot find. From what I have been reading, I see that the factory method pattern allows you to define how to create a single…
601
votes
13 answers

When would you use the Builder Pattern?

What are some common, real world examples of using the Builder Pattern? What does it buy you? Why not just use a Factory Pattern?
Charles Graham
  • 24,293
  • 14
  • 43
  • 56
1
2 3
99 100