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# Service Layer Design Pattern

We are looking into creating a new project and are wanting to explore using the Repository and Service layer patterns, the aim to is create loosely coupled code which is fully testable using mock repositories. Please see below the basic…
user1223218
  • 131
  • 1
  • 1
  • 3
13
votes
3 answers

Designing a questiion-and-answer system that is flexible and efficient

I've been working on a dynamic question-and-answers system, but I'm having trouble creating a efficient AND flexible design for this system. I'd love to know if there's an established design pattern or any recommendations for designing this…
Scott Rippey
  • 15,614
  • 5
  • 70
  • 85
13
votes
3 answers

static method patterns for constructor functions in javascript

function Foo(){...} Foo.bar = function (){...}; Is this the only pattern for adding a static method to a constructor function? In particular, is it not possible to create the static method bar() within the definition of Foo() itself?
osoviejo
  • 481
  • 6
  • 17
13
votes
1 answer

Python - how to implement Bridge (or Adapter) design pattern?

I'm struggling with implementing the Bridge design pattern (or an alternative such as Adapter) in Python I want to be able to write code like this to dump database schemas based on a supplied URL: urls = ['sqlite://c:\\temp\\test.db',…
Dave
  • 391
  • 1
  • 4
  • 7
13
votes
3 answers

How to check if ManualResetEvent has been disposed, when trying to Set() it inside an EventHandler?

I have the following design pattern: var myObjectWithEvents = new ObjectWithEvents(); using (var mre = new ManualResetEvent(false)) { var onEvent = new EventHandler((sender, e) => { mre.Set(); }); try { …
Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
13
votes
2 answers

What is a proper implementation of the IAsyncResult interface?

I'm looking into adding some flexibility to a class that I've created which establishes a connection to a remote host and then performs an exchange of information (a handshake). The current implementation provides a Connect function which…
Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151
13
votes
3 answers

Should a Service class be singleton in java?

While designing a service class should it be singleton in java? Generally DAO is made singleton, so should the calling Service class be made singleton also?
Jyotirup
  • 2,882
  • 9
  • 30
  • 38
13
votes
2 answers

EF 4.2 Code First and DDD Design Concerns

I have several concerns when trying to do DDD development with EF 4.2 (or EF 4.1) code first. I've done some extensive research but haven't come up with concrete answers for my specific concerns. Here are my concerns: The domain cannot know about…
13
votes
2 answers

Front Controller vs. Façade pattern

Okay, I have done a bit of searching online and found this thread, but it still does not quite clear it up for me. What exactly is the difference between a Front Controller Pattern and a Façade pattern? As I understand it so far: A Façade pattern…
Gineer
  • 2,358
  • 4
  • 26
  • 40
13
votes
6 answers

Hierarchical Enums in C++

I'm working on a message parser/generator subsystem. I'm creating an auto-generator that uses a database that contains all of the information about this protocol, including enum lists, to generate the code. One thing I came across is the need for…
John Price
  • 556
  • 1
  • 6
  • 18
13
votes
2 answers

Dependency injection container? What does it do?

I have been reading up on DI and it seems like a simple enough concept. What I don't get is the container. Let’s say for a moment that I want to create my own container. Verbs like "detect" are used and I don't get how the container "detects" that a…
Elad Lachmi
  • 10,406
  • 13
  • 71
  • 133
13
votes
4 answers

Where does the AppDelegate file fit into MVC?

I'm learning iPhone/iPad programming. I believe I understand the concept of MVC; what I'm having difficulty with is understanding how some of the files in a normal iPhone/iPad application fit into MVC. When you create a new application using the…
13
votes
2 answers

C# how to "register" class "plug-ins" into a service class? - As of today

6 Years have passed since this question was made and I was expecting to have an easy solution today.. but seems not. NOTE: please read the other question to understand the concept: After a few minutes I tried to implement an easy example and I've…
Dryadwoods
  • 2,875
  • 5
  • 42
  • 72
13
votes
1 answer

Implementing the Producer/Consumer Pattern in C#

How can I implement the Producer/Consumer patterns in C# using Events and Delegates? What do I need to keep an eye out for when it comes to resources when using these design patterns? Are there any edge cases I need to be aware of?
tush1r
  • 19,443
  • 14
  • 36
  • 35
13
votes
3 answers

Singleton - Protected vs Private Constructor

When designing singletons, why is the constructor made protected and not private? This is based on what I've seen over the web. We want to control the number of instances made of that class, fair enough, but why protected? Wouldn't private do the…
Ron_s
  • 1,429
  • 1
  • 14
  • 24