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
13
votes
2 answers

Design patterns for social networking site like facebook?

I am interested in understanding the design principals to use to create the backend for a social networking site. I read up a few resources and found that facebook uses a graph as an underlying data structure where each node could be user/page/album…
smitten11
  • 187
  • 1
  • 2
  • 6
13
votes
3 answers

Why do we need to use the builder design pattern when we can do the same thing with setters?

public class Employee { private String name; private String address; private int id; public Employee() { // TODO Auto-generated constructor stub } @Override public String toString() { return "Employee…
Priyanka Taneja
  • 515
  • 1
  • 5
  • 21
13
votes
2 answers

Design a file system

What should be the classes that one needs to create while designing a file system . What kind of of design patterns should be used in designing the file system.
Niks
  • 163
  • 1
  • 1
  • 3
13
votes
6 answers

which design pattern to use for filtering query? c#

I have a database table with a list of products (clothing). The products belong to categories and are from different stores. Sample categories: tops, bottoms, shoes Sample stores: gap.com, macys.com, target.com My customers can request to filter…
ijdk
13
votes
4 answers

What objects should you return from the data access layer to the business layer an n-tier system

If you have, for example, a database table called Person (ID,Name etc) what kind of object should the data access tier return to the business tier? I'm thinking something like this: //data access tier public class DataAccess{ public interface…
Matthew Dresser
  • 11,273
  • 11
  • 76
  • 120
13
votes
2 answers

To what extent modern C++ obviate the need for design patterns?

The Design Patterns book by GoF which came out in 1994 was written with C++ like languages in mind and many of the code examples were given in C++. Programmers of other languages felt that their languages did not need these 23 design patterns as…
P.W
  • 26,289
  • 6
  • 39
  • 76
13
votes
4 answers

Why doesn't Closure Compiler recognize type declarations inside a self-executing anonymous function?

I'm getting a lot of "Unknown type" warnings when running a fairly large library through Closure Compiler, and they seem to occur when my types are declared in self-executing anonymous functions. There's nothing exotic about this, but if I strip the…
jpdaigle
  • 1,265
  • 10
  • 12
13
votes
2 answers

Singleton of Java functional interface as enum

While looking at the source code of the Comparators class, I came across these lines of code. class Comparators { //... enum NaturalOrderComparator implements Comparator> { INSTANCE; @Override …
Yeater
  • 155
  • 5
13
votes
5 answers

C++ Iterator Pipelining Designs

Suppose we want to apply a series of transformations, int f1(int), int f2(int), int f3(int), to a list of objects. A naive way would be SourceContainer source; TempContainer1 temp1; transform(source.begin(), source.end(), back_inserter(temp1),…
kirakun
  • 2,770
  • 1
  • 25
  • 41
13
votes
1 answer

Pattern for Javascript Module Pattern and Sub-Module Initialization

I am starting up a new project and I am reviewing my best-practices to try to prevent any problems, and also to see what bad habits I have gotten into. I am not terribly pleased with how I am handling initialization sequences in Javascript using the…
mpdonadio
  • 2,891
  • 3
  • 35
  • 54
13
votes
4 answers

Struct with optional members in modern C++

We have inherited old code which we are converting to modern C++ to gain better type safety, abstraction, and other goodies. We have a number of structs with many optional members, for example: struct Location { int area; QPoint…
user9088793
13
votes
3 answers

Appropriate design pattern for the payment modules c#

As i am learning through design pattern concept and also wanted to implement the payment modules in my project using the proper design pattern. So for that I have created some sample code. Currently I have two concrete implementation for the…
Rasik
  • 1,961
  • 3
  • 35
  • 72
13
votes
2 answers

Are middlewares an implementation of the Decorator pattern?

In Django, there is the idea of Middleware. It consists of changing the requests and passing it down to the next middleware and so on, and doing the reverse with the responses. Are middlewares implementation of the design pattern Decorator? Are they…
thyago stall
  • 1,654
  • 3
  • 16
  • 30
13
votes
7 answers

Pattern to share data between objects in C++

I have started a migration of a high energy physics algorithm written in FORTRAN to an object oriented approach in C++. The FORTRAN code uses a lot of global variables all across a lot of functions. I have simplified the global variables into a set…
smancill
  • 744
  • 1
  • 6
  • 13
13
votes
2 answers

Microservice architecture - carry message through services when order doesn't matter

Tl;dr: "How can I push a message through a bunch of asynchronous, unordered microservices and know when that message has made it through each of them?" I'm struggling to find the right messaging system/protocol for a specific microservices…