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

DTO conveter pattern in Spring Boot

The main question is how to convert DTOs to entities and entities to Dtos without breaking SOLID principles. For example we have such json: { id: 1, name: "user", role: "manager" } DTO is: public class UserDto { private Long id; private…
Maksym
  • 2,650
  • 3
  • 32
  • 50
13
votes
2 answers

DDD: Where to put persistence logic, and when to use ORM mapping

We are taking a long, hard look at our (Java) web application patterns. In the past, we've suffered from an overly anaemic object model and overly procedural separation between controllers, services and DAOs, with simple value objects (basically…
optilude
  • 3,538
  • 3
  • 22
  • 25
13
votes
1 answer

Clean architecture. What are the jobs of presenter?

I have been reading some articles about the clean architecture, and how it can be implemented in android. I saw the sample app which shows its Android Implementation. Also, I went through a nice talk on Clean architecture on Android So, I kind of…
user4260260
13
votes
4 answers

Observer pattern or Callback?

I have to do a design of a DownloadManager, but my main question is related to the notifications that a Download can send to the DownloadManager like onUpdate() to update a progress bar, onError(), onFinish(), etc. Somehow the DownloadManager has to…
Gabriel Llamas
  • 18,244
  • 26
  • 87
  • 112
13
votes
4 answers

How to improve Cyclomatic Complexity?

Cyclomatic Complexity will be high for methods with a high number of decision statements including if/while/for statements. So how do we improve on it? I am handling a big project where I am supposed to reduced the CC for methods that have CC > 10.…
yeeen
  • 4,911
  • 11
  • 52
  • 73
13
votes
5 answers

implement DDD in MVC Frameworks - PHP

in mvc the model is a layer and it's contain all the domain business logic. in domain driven design business logic can be divide into various building blocks like. in Domain Driven Design domain model is. A domain model is a system of abstractions…
13
votes
1 answer

Swift: The proper way to initialize model class with a lot of properties

How do you initialize your classes/structs with a lot of properties? This question could probably be asked without Swift context but Swift brings a flavour to it, so I add Swift tag in headline and tags. Let's say you have a User class with 20…
user1264176
  • 1,118
  • 1
  • 9
  • 26
13
votes
4 answers

How to implement retry policies while sending data to another application?

I am working on my application which sends data to zeromq. Below is what my application does: I have a class SendToZeroMQ that send data to zeromq. Add same data to retryQueue in the same class so that it can be retried later on if acknowledgment…
john
  • 11,311
  • 40
  • 131
  • 251
13
votes
7 answers

How to model an amount of Money in Java

Can anybody recommend a class library or a design pattern that models amounts of Money? I guess it should support: multiple currencies a mechanism to indicate the number of decimals math (respecting certain rounding conventions (cfr ie. Banker's…
Jan
  • 9,397
  • 13
  • 47
  • 52
13
votes
7 answers

How to remove objects from an Enumerable collection in a loop

Duplicate Modifying A Collection While Iterating Through It Has anyone a nice pattern to allow me to get around the inability to remove objects while I loop through an enumerable collection (eg, an IList or KeyValuePairs in a dictionary) For…
johnc
  • 39,385
  • 37
  • 101
  • 139
13
votes
2 answers

Where do operations on models belong in Application Design Patterns?

Say we want to make an application containing the following: Asynchronous and time consuming operations on selected objects For a certain object we want to access the status of an associated operation. The ability to show, cancel and pause these…
13
votes
2 answers

Fast undo/redo for bitmap editor when memory is limited?

I'm trying to write a bitmap editor for a mobile device (i.e. a limited version of Photoshop). The user's document consists of ~4 bitmaps around 1000x500 in size each. I want a robust and efficient undo/redo system that's as simple as possible. I'm…
memcom
  • 635
  • 1
  • 5
  • 10
13
votes
2 answers

Advice on POCO Validation with ASP.NET MVC/Entity Framework

Here's the scenario: ASP.NET MVC2 Web Application Entity Framework 4 (Pure POCO's, Custom Data Context) Repository Pattern Unit of Work Pattern Dependency Injection Service Layer mediating Controller -> Repository So basically, all the cool stuff.…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
13
votes
4 answers

What is this pattern called?

string s = new string("Hello World").Replace(" ","_").ToLower().ToUpper(); So you basically return from each method the modified object so can you call new methods on it.
Gol
  • 131
  • 2
13
votes
5 answers

How can i structure a program (proces) with a very high number of IF statements

i have to create a program for a kind of complex proces. Well, the process is not complex, but there are a lot of variables which control the process. I can't in detail tell about the process, so i've made up one, which has the same load of…
Michel
  • 23,085
  • 46
  • 152
  • 242