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
7 answers

What are real-world examples of C++ multiple inheritance?

Besides textbook examples -- in the real world -- does it ever make sense to use multiple inheritance (where more than one of the base classes are not pure interfaces) in C++?
anon
  • 41,035
  • 53
  • 197
  • 293
13
votes
2 answers

Powershell scripting: recommended way to implement ShouldProcess when function calls are nested?

Test script: function outer { [cmdletbinding(supportsshouldprocess=$true)] param($s) process { $pscmdlet.shouldprocess("outer $s", "ShouldProcess") | out-null "" | out-file "outer $s" inner…
Richard Berg
  • 20,629
  • 2
  • 66
  • 86
13
votes
4 answers

bridge pattern vs. decorator pattern

Can anybody elaborate the Bridge design pattern and the Decorator pattern for me. I found it similar in some way. I don't know how to distinguish it? My understanding is that in Bridge, it separate the implementation from the interface, generally…
skydoor
  • 25,218
  • 52
  • 147
  • 201
13
votes
2 answers

Automatic generation of immutable class and matching builder class

What tools/libraries exist that will take a struct and automatically generate an immutable wrapper and also a "builder" class for incrementally building new instances? Example input: struct Foo { public int apples; public int oranges; …
finnw
  • 47,861
  • 24
  • 143
  • 221
13
votes
2 answers

Refactoring abstract class in C#

Sorry if this sounds simple, but I'm looking for some help to improve my code :) So I currently have the following implementation (which I also wrote): public interface IOptimizer { void Optimize(); string OptimizerName { get; } } public…
alhazen
  • 1,907
  • 3
  • 22
  • 43
13
votes
5 answers

Single Responsibility Principle(SRP) and class structure of my rpg looks "weird"

I'm making a role playing game just for fun and to learn more about the SOLID principles. One of the first things I'm focusing on is SRP. I have a "Character" class that represents a character in the game. It has things like Name, Health, Mana,…
mikedev
  • 733
  • 9
  • 16
13
votes
4 answers

Where to find User Interface (UI) design patterns for Windows applications?

I don't know if this question really suits here, but we'll see :) For web applications there are sites like Pattern Tap and UI-patterns, which have a great collection of design patterns used in UI's. I can't seem to find any websites/books/articles…
MysticEarth
  • 2,646
  • 4
  • 33
  • 53
13
votes
3 answers

How can the proxy pattern be used to replace a singleton?

This is in response to some comments in what is so bad about singletons There it was suggested that the proxy pattern can be used instead of a singleton to cache DB data. But I cannot see the advantage, and in fact the singleton seems more…
Dai Bok
  • 3,451
  • 2
  • 53
  • 70
13
votes
2 answers

Query Object Pattern (Design Pattern)

I need to implement a Query Object Pattern in Java for my customizable search interface (of a webapp I'm writing). Does anybody know where I can get an example/tutorial of Query Object Pattern (Martin Fowler's QoP)? Thanks in Advance ADDITION How to…
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
13
votes
3 answers

Pass DTO to service layer

Is it not bad practice to pass DTO object to service layer? For now my service layer method look like this: public save(MyEntity entity); Mapping values from DTO to business entity (MyEntity) is done on presentation layer But I want to change…
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286
13
votes
4 answers

Repository vs Service pattern in DAL: EF and Dapper

I'm working on project and I need to design the DAL. I will be using Entity Framework for most of the project and Dapper for some performance-sensitive areas. I was thinking about using the Repository pattern but then EF already implements this…
sakura-bloom
  • 4,524
  • 7
  • 46
  • 61
13
votes
3 answers

Akka Pattern - Actor tree, reply to original source

This is a design question; Say I have a tree of actors which do a bunch of processing. The processing is kicked off by a client/connection actor (i.e. the tree is the server). Eventually the client actor wants a response. I.e. I have an actor…
NightWolf
  • 7,694
  • 9
  • 74
  • 121
13
votes
4 answers

Design Pattern to track partial results of a complex process

I'm facing a programming problem that I don't know how to solve in a object oriented and flexible way. I have in mind some bad solutions, but I'm searching for a good one. I develop in Java, so I prefer Java ideas, but any object oriented idea is…
Matyf
  • 131
  • 1
  • 7
13
votes
6 answers

Open Session In View Pattern

I'm asking this question given my chosen development frameworks of JPA (Hibernate implementation of), Spring, and . I've been thinking a bit about relationships in my entity…
JMM
  • 3,922
  • 6
  • 39
  • 46
13
votes
3 answers

What is the best approach in python: multiple OR or IN in if statement?

What is the best approach in python: multiple OR or IN in if statement? Considering performance and best pratices. if cond == '1' or cond == '2' or cond == '3' or cond == '4': pass OR if cond in ['1','2','3','4']: pass
Jonathan Simon Prates
  • 1,122
  • 2
  • 12
  • 28