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
12
votes
1 answer

Using JAXB to support schemas with minor variations

The Situation I need to support generating XML documents based on schemas that vary only slightly between each other. Specifically, the schemas that I need to support are based on industry standards that change slightly over time and vendors may…
Terence
  • 706
  • 9
  • 22
12
votes
2 answers

Visitor Pattern in Objective-C

I've been looking at the best way to implement the Visitor design pattern in Objective-C. Since the language doesn't support method overloading, a 'traditional' implementation such as one might find in Java seems impossible. In my current…
Simon Withington
  • 1,485
  • 2
  • 11
  • 17
12
votes
1 answer

factory method (1) vs factory(2) vs Builder (3) pattern

What is use cases for use (1),(2),(3). What is pro & cons to use it. What is difference between them?
Ph0en1x
  • 9,943
  • 8
  • 48
  • 97
12
votes
1 answer

ExtJS (JavaScript) Module Design Pattern best practices

I have a question about best practices with the Module Design Pattern. The code below is an example of the way that some of our Components are written (we use ExtJs but that shouldn't matter too much). We build a lot of our components like this…
blong
  • 2,815
  • 8
  • 44
  • 110
12
votes
13 answers

If I have limited time to learn a few design patterns, which ones should I learn?

If I have limited time, but I want to start learning a few design patterns, which ones should I learn first?
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
12
votes
4 answers

When is using instanceof the right decision?

As I've always understood it, the main cases where an instanceof is appropriate are: Implementing Object.equals(Object). So if I were writing a List class, and not extending AbstractList for whatever reason, I would implement equals(o) by first…
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
12
votes
8 answers

What should come first -- the design pattern or the code?

I'm starting on a fresh new project--should I look at my spec and decide which design patterns to apply, or just come up with a general idea of organization and allow the patterns to emerge organically through refactoring? In your experience, which…
alchemical
  • 13,559
  • 23
  • 83
  • 110
12
votes
3 answers

what reasons are there to use interfaces (Java EE or Spring and JPA)

Most of the J2EE(Spring and JPA) classes are designed with interfaces. Except for inheritance, are there any technical reasons for this? Like dynamic proxy or AOP, I need more technical details about this ex public interface UserDAO { void…
Arun
  • 1,167
  • 18
  • 37
12
votes
2 answers

Get result of executed method in Command Pattern

Currently I'm trying to implement Transaction Script pattern (Exactly how Martin Fowler described by using Command Pattern) in a simple test project, everything just work fine, the problem is where I don't know how to get result(s) when specified…
Saber Amani
  • 6,409
  • 12
  • 53
  • 88
12
votes
7 answers

Making a class singleton without using static method

I need to create a singleton class without keeping a static method. How can i do that?
Sunny Gupta
  • 6,929
  • 15
  • 52
  • 80
12
votes
2 answers

C# Dto constructor and dependency injection

I would like to know what is the best practice in designing the constructors of DTO objects. say i have a Dto object like this: class CustomerDto { public string Name { get; set; } public string Surname { get; set; } public string Phone…
Andre
  • 3,717
  • 4
  • 25
  • 29
12
votes
2 answers

Leader/Follower vs work queue

I've just read a paper about the Leader/Follower Pattern and if I understood correctly, I keep my workers in a queue and the first worker takes an incoming request and detaches from the queue. With a normal work-queue (rabbitmq and beanstalkd, for…
Nicolas
  • 1,828
  • 6
  • 23
  • 34
12
votes
1 answer

How to unit test a state machine?

Suppose I have an Order class, which can be in three different states : CheckedState, PaidState and OrderedState. The state machine will be implemented using the standard State Design Pattern (Gof). How do you usually unit test this? Do you use a…
Riana
  • 689
  • 6
  • 22
12
votes
3 answers

AbstractFactory Versus Bridge Pattern

I have just learned the Bridge Pattern and its intent : Decouple an abstraction from its implementation so that the two can vary independently. But why couldn't just an AbstractFactory do the same thing ? I know that an AbstractFactory can create a…
Mik378
  • 21,881
  • 15
  • 82
  • 180
12
votes
2 answers

What is the fastest way to calculate frequency distribution for array in C#?

I am just wondering what is the best approach for that calculation. Let's assume I have an input array of values and array of boundaries - I wanted to calculate/bucketize frequency distribution for each segment in boundaries array. Is it good idea…
1 2 3
99
100