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

Design pattern good for many entities history?

I have some entity classes in my application. I want to save all changes to this entities and some happened events in a history table. Problem is that entity classes are different, build with different primitives and different relation between…
Tomasz Kalkosiński
  • 3,673
  • 1
  • 19
  • 25
13
votes
1 answer

What is the Serialization Proxy Pattern?

Alas, Google has failed me... What is the Serialization Proxy Pattern and where can I learn more about implementing and using it?
urig
  • 16,016
  • 26
  • 115
  • 184
13
votes
3 answers

Difference between Proxy pattern and Virtual proxy pattern

I knew of the proxy pattern till now and recently read this article that says a virtual proxy is basically used to defer the Object Creation process of memory-intensive components thereby speeding up the Application. But after reading that article…
user20358
  • 14,182
  • 36
  • 114
  • 186
13
votes
5 answers

Objective-C - Is !!BOOL Beneficial

I'm looking over the diffs submitted to a project by another developer, and they have a lot of code that does !!. In fact, this seems to be their standard pattern for implementing boolean getters and setters. They've implemented…
aroth
  • 54,026
  • 20
  • 135
  • 176
13
votes
6 answers

Lightweight wrapper - is this a common problem and if yes, what is its name?

I have to use a library that makes database calls which are not thread-safe. Also I occasionally have to load larger amounts of data in a background thread. It is hard to say which library functions actually access the DB, so I think the safest…
foraidt
  • 5,519
  • 5
  • 52
  • 80
13
votes
4 answers

Functional Equivalent of State Design Pattern

What would be the functional programming equivalent of the State design pattern? Or more concretely, how would this Wikipedia example of State design pattern will translate to FP?
13
votes
3 answers

node.js design pattern for creating db connection once

I am looking for help with a design pattern for creating a database connection in my node.js application. It seems obvious to do: module1: var db; exports.get_db = function(callback) { if (db == null) { dblibrary.create(connection_params,…
MarcWan
  • 2,943
  • 3
  • 28
  • 41
13
votes
1 answer

Are there any good examples on how to organize JavaScript code?

I've learned JavaScript and know how to write OO JavaScript, and I can accomplish those assignment like autocomplete, photo gallery with JavaScript, but I just don't know how to organize the codes. For example, when and where to define a function,…
wong2
  • 34,358
  • 48
  • 134
  • 179
13
votes
7 answers

What methods should go in my DDD factory class?

I am struggling to understand what my factory class should do in my DDD project. Yes a factory should be used for creating objects, but what exactly should it be doing. Consider the following Factory Class: public class ProductFactory { …
Th3Fix3r
13
votes
6 answers

Writing OO Javascript with jQuery

I come from a Prototype JS background where OO Javascript is encouraged through the use of Class.create(). Now I am doing some JQuery work and I am trying to write some properly structured JQuery code where I can, for example, call the same object…
Ciaran Archer
  • 12,316
  • 9
  • 38
  • 55
13
votes
1 answer

What is the best way to marshall data in/out of the plug-ins?

I am building my workstation Agent application using MEF and EntityFramework 4. The application is a simple agent that runs on a computer with a plug-in architecture (and many plugins in the form of .dll files). Each plug-in will query their own…
s0ftimage
  • 175
  • 8
13
votes
1 answer

What design pattern can I use to emulate traits / mixins in PHP?

Since traits aren't available in PHP 5.3 AFAIK I need to emulate some of the functionality they offer. Interfaces won't work because I need concrete functionality. Problem: I have two client classes that need to share some functionality but extend…
james
  • 3,543
  • 8
  • 31
  • 39
13
votes
2 answers

Best way to hide/disable GUI elements based on user's privilege?

I am starting a web application with client side implemented in pure ExtJS and middle tier in Grails. The application has role-based authorization, where a user can have many fine grained roles like SOME_FORM_READ, SOME_FORM_UPDATE,…
Tong Wang
  • 1,602
  • 4
  • 29
  • 36
13
votes
4 answers

Examples of functional or dynamic techniques that can substitute for object oriented Design Patterns

This is somewhat related to Does functional programming replace GoF design patterns? Since the introduction of lambdas and dynamics in C#, are there any of the standard design patterns that could be considered obsolete or solved in some other way…
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
13
votes
3 answers

Books specifically on Software Architecture and not Software Design

Can you please suggest some books on Software Architecture, which should talk about how to design software at module level and how those modules will interact. There are numerous books which talks about design patterns which are mostly low level…
Invincible
  • 795
  • 3
  • 10
  • 17