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
14
votes
2 answers

Implementing the command pattern

I am in the design process of an application, and I would like to use the command pattern for undo/redo purposes. I did some research into the command pattern but the only thing I don't get is: Should a command have the undo and redo methods, or…
slayerIQ
  • 1,488
  • 2
  • 13
  • 25
14
votes
3 answers

Software Design Website(s)

What websites (not books) document designs (UML or otherwise) for software applications? Building architects have many resources available for inspiration and construction. I do not seek resources on constructing software (such as Meyer's…
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
14
votes
4 answers

empty function object in python

I've heard that python functions are objects, similar to lists or dictionaries, etc. However, what would be a similar way of performing this type of action with a function? # Assigning empty list to 'a' a = list() # Assigning empty function to…
chase
  • 3,592
  • 8
  • 37
  • 58
14
votes
2 answers

SQL Database Best Practices - Use of Archive tables?

I'm not a trained DBA, but perform some SQL tasks and have this question: In SQL databases I've noticed the use archive tables that mimic another table with the exact same fields and which are used to accept rows from the original table when that…
matrix4use
  • 611
  • 1
  • 6
  • 20
14
votes
10 answers

"Adapter" or "adaptor"?

In programming, which spelling—adapter or adaptor—is standard or de facto standard? Is there a difference between them? In boost I see "adaptor", whereas in literature I see "adapter". Which one is preferred in code?
Anycorn
  • 50,217
  • 42
  • 167
  • 261
14
votes
5 answers

My class derived from SQLiteOpenHelper is getting huge

My class derived from SQLiteOpenHelper is getting bigger and bigger over a time. At the speaking time it is more than 1500 lines of code which is not considered to be cool. There might be some elegant solution to prevent it from growing, i.e.…
Eugene
  • 59,186
  • 91
  • 226
  • 333
14
votes
2 answers

Standard Naming Convention for DAO Methods

Is there a standard naming convention for DAO methods, similar to JavaBeans? For example, one naming convention I've seen is to use get() to return a single entity and find() to return a List of entities. If there isn't one, what's the one your team…
Tom Tucker
  • 11,676
  • 22
  • 89
  • 130
14
votes
4 answers

Fluent APIs - return this or new?

I recently came up to an interesting question, what should fluent methods return? Should they change state of current object or create a brand new one with new state? In case this short description is not very intuitive here's an (unfortunaltely)…
Rustam
  • 1,766
  • 18
  • 34
14
votes
5 answers

How is loose coupling achieved using interfaces in Java when an implementation class is mandatory and bound to interface contract?

How is loose coupling associated with interfaces when we are bound to create an implementation class regardless? The implementation class is forced to implement all those methods defined in the interface. I don't understand how this allows for lose…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
14
votes
2 answers

why inheritance is strongly coupled where as composition is loosely coupled in Java?

I have heard this favor composition over inheritance again and again in design patterns. some of the reasons cited for this are 1)Inheritance is strongly coupled where as composition is loosely coupled 2) Inheritance is compile time determined where…
brain storm
  • 30,124
  • 69
  • 225
  • 393
14
votes
2 answers

AngularJS design patterns: Should I use factories to create constructor functions?

This is something I've been mulling over while creating an AngularJS app. When I first learned about AngularJS factories, I thought one clever usage of them would be to create and return a constructor function rather than a plain object, i.e.…
brainkim
  • 902
  • 3
  • 11
  • 20
14
votes
6 answers

How to run code inside a loop only once without external flag?

I want to check a condition inside a loop and execute a block of code when it's first met. After that, the loop might repeat but the block should be ignored. Is there a pattern for that? Of course it's easy to declare a flag outside of the loop. But…
danijar
  • 32,406
  • 45
  • 166
  • 297
14
votes
2 answers

Calling chains methods with intermediate results

I have a class and some methods of it. Could I keep a result of the methods between calling. Example calling: result = my_obj.method_1(...).method_2(...).method_3(...) when method_v3(...) received a result from the method_2(..) who received a…
Abbasov Alexander
  • 1,848
  • 1
  • 18
  • 27
14
votes
8 answers

Is there a design pattern for dealing with large datasets over the internet?

I am looking for a design pattern that handles large data sets over the internet, and does periodic updating of these objects. I am developing an application that will display thousands of records in the UI at one time. Additionally, various…
Jason Jackson
  • 17,016
  • 8
  • 49
  • 74
14
votes
3 answers

What is the best method for making database connection (static, abstract, per request, ...)?

I used lot of model for connecting to db, in my last project that i worked with C# & entity framework, i created static class for db connecting but i had problem with opening and closing connection for that give me error when more than 10-15…
Mehdi Yeganeh
  • 2,019
  • 2
  • 24
  • 42