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

C++ Design Pattern library?

What is the most common C++ Design Pattern libraries? I've read about Loki library in Alexandrescu's book, but looks like it somewhat dead now. Is there something similar out there?
cody
  • 3,233
  • 1
  • 22
  • 25
13
votes
3 answers

Java library to return a List for glob or Ant-like pattern "*foo/**/*.txt"?

I'm looking for a lib which would provide a method which would give me a list of files matching given Ant-like pattern. For *foo/**/*.txt I'd get foo/x.txt foo/bar/baz/.txt myfoo/baz/boo/bar.txt etc. I know it's achievable with DirWalker and…
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
13
votes
5 answers

MVVM : Share data between ViewModels

How do I share data between multiple ViewModels ? For example there is a class named Project in application . public class Project : ModelBase { private string _projectName; public string ProjectName { get { return…
Unforgiven
  • 1,999
  • 5
  • 19
  • 18
13
votes
3 answers

When and how should I use enumeration classes rather than enums?

A developer at work recently started using a class pattern instead of enums in places where enums would usually fit. Instead, he uses something similar to that below: internal class Suit { public static readonly Suit Hearts = new Suit(); …
13
votes
1 answer

boost::asio and Active Object

I have implemented some module based Active Object design pattern. It is very simple implementation. I have Scheduler, ActivationList, Requests and Futures to get response. My requirements were like that: Access to active object shall be serialized…
user2301299
  • 529
  • 1
  • 5
  • 15
13
votes
3 answers

GUI as a finite state machine

To implement application's GUI I would like to have all the logic to go from one form to another centralized. This GUI manager will behave as a finite state machine. Although I think I have seen this kind of implementation somewhere, I can't find a…
yeyeyerman
  • 7,751
  • 7
  • 43
  • 52
13
votes
4 answers

Unable to understand need to make Process.java abstract

I was casually walking through source code of Java core classes. I found that Process.java file is an public abstract class. When I went through code No function have definition. Does that mean that it should have been declared an Interface. Is…
Aman J
  • 1,825
  • 1
  • 16
  • 30
13
votes
4 answers

Is the Composite Pattern SOLID?

A Leaf in the Composite Pattern implements the Component interface, including Add, Remove, and GetChild methods that a Leaf is never going to use. This seems to be a violation of the Interface Segregation Principle. So is the usage of Composite…
13
votes
7 answers

Delphi: Good pattern/strategy for view <-> model synchronization

There's a lot of talk about model-view-controller, model-view-viewmodel, model-view-presenter and so on these days. What do you see as the best pattern for use with delphi and non-data aware components? How do you usually implement it?
Vegar
  • 12,828
  • 16
  • 85
  • 151
13
votes
5 answers

Is "string-free coding" a common term?

Recently i get in touch with Empire-db. The project doc. stated that they are using "string-free coding", intended to use less constant strings as possible to avoid typos and use the force of the compiler. I was always a big fan of this principle,…
PeterMmm
  • 24,152
  • 13
  • 73
  • 111
13
votes
2 answers

The Observer Pattern - further considerations and generalised C++ implementation

A C++ MVC framework I’m writing makes heavy use of the observer pattern. I have had a thorough read of the related chapter in Design Patterns (GoF, 1995) and had a look at a multitude of implementations in articles and existing libraries (including…
Izhaki
  • 23,372
  • 9
  • 69
  • 107
13
votes
7 answers

Overriding Methods vs Assigning Method Delegates / Events in OOP

This is a bit of an odd oop question. I want to create a set of objects (known at design time) that each have certain functions associated with them. I can either do this by giving my objects properties that can contain 'delegates': public class…
Flash
  • 15,945
  • 13
  • 70
  • 98
13
votes
3 answers

Best Practices For Heavy Computations in Javascript?

I am working on client side scripts and need to do heavy computations like pushing huge number of objects in an array, it causes JavaScript to stop response and browser hangs giving an alert: Is there any best practices or design patterns for…
Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
13
votes
6 answers

Factory Pattern where should this live in DDD?

I have debated this for a while now and still have not come to a conclusion. While most examples I see have the factories code in the application layer I tend to think it should be in the domain layer. Reasons for this: I sometimes have initial…
13
votes
6 answers

what is the difference between visitor and strategy pattern?

I have learned both the patterns but did not understand the differences between these two patterns. I do not know scenarios, when and where to use these patterns. Can any one explain the differences and use cases?