A design pattern is a general reusable solution to a commonly occurring problem in software design.

learn more… | top users | synonyms (1)

27
votes
14answers
2k views

Is there a language or design pattern that allows the *removal* of object behavior or properties in a class hierarchy?

A well-known shortcoming of traditional class hierarchies is that they are bad when it comes to modeling the real world. As an example, trying to represent animals' species with classes. There are ...
4
votes
2answers
95 views

Go - idioms/design for determining when an unknown number of goroutines are complete

I have a workflow wherein I walk recursively through a bunch of directories, then for each file perform some action. I'm using goroutines to walk each directory, and also to process each file. The ...
1
vote
2answers
189 views

Design of an online book reader

I want to design an online book reader system as a programming exercise. I wrote down the following requirements: Searching a book by title. Bookmarking a book. Mark a book as favorite. Give rating. ...
3
votes
2answers
411 views

Preventing Liskov Substitution violation

I am reimplementing some component and noticed that the original version has a Liskov Substitution violation. It's not all that critical, though I'd like to get rid of it in the new implementation . ...
15
votes
1answer
976 views

Does Liskov Substitution Principle also apply to classes implementing an interface?

LSP states that classes should be substitutable for their base classes, meaning that derived and base classes should be semantically equivalent. But does LSP also apply to classes implementing an ...
1
vote
2answers
141 views

MVC - Database search logic in View or Model

Special Note: I asked a very similar question on Stack Overflow, but I have since decided the problem should be solved from a design standpoint rather than an implementation standpoint. I have ...
2
votes
1answer
90 views

Message Mapper Design Considerations

Long question context, skip to tl;dr for the meat of it. I am designing an integration between two web applications, and have come to the conclusion that a message pattern would be an appropriate ...
0
votes
1answer
42 views

Full data history, current values can be rebuilt ignoring provisional or invalidated changes

I would like to create a website for a local school and then offer it to others. The school's main headache at the moment is capturing student marks and comments at the end of each school term. The ...
0
votes
1answer
92 views

Design Pattern for Object Updates

I have a "Product" class that has some ID, and multiple other fields, and a function updateProduct(id, Product update). The intention is that "update" only contains the changed information - other ...
2
votes
5answers
246 views

Constructor overloading or allow null?

Which is the preferred design to use, one constructor that allows null, or two constructors where one throws an ArgumentNullException on null? Two constructors with exception throwing public class ...
22
votes
8answers
4k views

How can I promote the use of the Builder pattern in my team?

Our codebase is old and new programmers, like myself, quickly learn to do it the way it's done for the sake of uniformity. Thinking that we have to start somewhere, I took it upon myself to refactor a ...
6
votes
2answers
225 views

MVP (Supervising Controller) Does the view update the model?

I've been reading about MVP, specifically Supervising Controller. One thing I'm having difficulty wrapping my head around is how the View interacts with the Model. It was my understanding that the ...
4
votes
3answers
438 views

Is Convention Over Configuration “Knowledge in the World” or “Knowledge In Your Head”?

In Don Norman's seminal work "The Design of Everyday Things", the author coined the phrases and explains the difference between "Knowledge in the World" and "Knowledge In Your Head"; an example of ...
0
votes
3answers
200 views

What kind of development am I doing?

I am doing a webapp for the internals in my company, it has been 8 months and now I want to become more professional about it, and to know precisely what I am doing. My workflow is to make little ...
2
votes
2answers
150 views

Reversible Functions

Currently writing a JSON Importer and creating some POJOs based on the data. I also have a requirement to write an JSON Exporter which take the information in the POJOs and exports a JSON doc. To me ...
0
votes
1answer
104 views

Design patterns for ERP software with clients and web service

I'll will make ERP software for managing data for business activities. The solution must have two big parts: a WPF application for all the clients and an ASP MVC Web API application for all the client....
6
votes
1answer
105 views

How to allow for custom Rules in a Entity Component System designed game engine?

So I've been doing a lot of research into game engines, and Entity Component System (ECS) seems to be the most flexible and extendable design to use. Just to summarize, in ECS the basic idea is that ...
7
votes
4answers
250 views

Encapsulation for complex queries

I tried asking this question first on StakOverflow in a more concrete manner, but after being pointed here I realized I should rephrase it in more general terms; however, you can still review the ...
6
votes
3answers
385 views

Best practices for using public, protected, private?

Is it fair to say that it is good practice to default everything to private up front when coding something? And then only upgrade it to protected if a subclass needs it, or public if another class ...
2
votes
1answer
61 views

Invoking Methods of another component in Observer Pattern

Question: Are there any techniques for communicating with methods of other components but still keep a "pure" Observer pattern ? If yes are they indicated/regularly-used or am I just ...
3
votes
2answers
213 views

Using MVC style, where is the best place to put SQL functionality?

I am wondering about best practices here. MVC (Model - View - Controller) patterns involve separating components of your program that model the data, manipulate those models, and display those ...
4
votes
0answers
103 views

Is the observer pattern suitable when the observers are not independent of each other?

I have a class Car which has 2 properties: int price and boolean inStock. It also holds a List of abstract class State (empty class). There are 2 states which can be applied on the car and each is ...
4
votes
1answer
53 views

What is the best pattern to define own type with definitive collection of values?

I want to define own data type, say a Digit, which would have definite type of values ( 0 to 9 ) and I'm struggling with defining this in a way it's practical. What's the best way (design pattern) to ...
5
votes
2answers
109 views

Design pattern for too many ctor parameters within class hierarchy

Is there some design pattern for handling situation where class hierarchy constructors parameters force the most bottom classes to have too many parameters? Ideally this would be in C++, if language ...
2
votes
1answer
138 views

Developing a calculator using the command pattern

In an attempt to solidify my understanding of the command pattern, I decided to write a calculator application that utilised it. After making some progress, I realised that my choice of application ...
5
votes
1answer
111 views

Partially parallel producer-consumer pattern with internal state

I need to implement a producer-consumer pattern for reading, processing and saving electrical values. I have to implement this in C# .NET 4.6.1. I try to describe this in great detail, so that there ...
7
votes
0answers
253 views

How do I associate command objects with the right receiver?

I tried to use Command Pattern for implementing Undo and Redo in my project public abstract class Command { protected Form Receiver { set; get; } protected HtmlElement Element { set; get; } ...
-1
votes
1answer
102 views

Is there an official name for the “one object disease” anti-pattern (iterative single object operations on databases, services etc.)?

It is caused by the naive programming paradigm: focus on just a single object, do something with it, and if you have to work with many objects, you loop, iterate and traverse, repeating the operation ...
4
votes
1answer
170 views

Am I using the factory method design pattern correctly, or which creational pattern should I use?

I've been studying creational design patterns for the past week or so because I have a common use case that keeps coming up, and I can't figure out which pattern fits the bill. Here is a simplified ...
0
votes
1answer
235 views

Rich Model vs God Class [duplicate]

I have a legacy code containing some behaviour classes, like services and controllers. My model is pretty anaemic. It's just a repository of getters and setters, and I want to refactor it. There is a ...
0
votes
2answers
146 views

C++ class vs function header file

I'm using C++ for implementing a project that requires to import a file once. All the data in this file needs to brought in memory as key value pairs, but only when the file is imported. Since this ...
2
votes
4answers
125 views

Are names like OrderCreation and UserRegistration suitable names for business logic / domain classes

We have moved to a more SRP model and found coming up with class names challenging. Previously we had a Order class that looked something like this: public class Order { public void Create() {...
6
votes
2answers
3k views

Should I put calculation logic in an Entity or in the Business Layer?

Recently I was faced a question about whether a simple calculation should be put in the Entity layer, or should the Entity be pure for just storing the raw data and leave the calculation logics in the ...
3
votes
4answers
238 views

Is Template Pattern a good way to implement DRY?

Here is my problem: I have and class structure like this: class Base { private: SomeType something; bool isSomeValue; public: virtual void myMethod() = 0; }...
7
votes
3answers
1k views

Immutable structures and deep composition hierarchy

I'm developing a GUI application, heavily working with graphics - you can think about it as a vector editor, for the sake of the example. It is very tempting to make all data structures immutable - so ...
2
votes
4answers
257 views

Reusing the logic in another repository in ASP.NET MVC repository pattern

I have an ASP.NET MVC4 web application, with EntityFramework for data access. In the application I have two repositories as follow (this is only an example not my real code): public class ...
3
votes
4answers
256 views

Defining logic without nested if-else statements

I'm working on a somewhat simple game. Currently trying to implement the game logic for moving the pieces around. Logic is something like this: does player have pieces in inventory? if yes: ...
6
votes
2answers
236 views

DDD: Creating reusable modules and service type distinctions (Domain, Infrastructure, Application)

So after reading "Implementing Domain-Driven Design by Vaughn Vernon" I've decided to refactor my code for better re usability by isolating what I believe to be core domain concepts into separate ...
1
vote
1answer
163 views

What could be the better c# design for following requirement? [closed]

I am working on creating a c# design for following requirement. I am creating this for a fitness website. I have an article (as Text) and a exercise (as Image or Videos) as the base entity. Now i ...
1
vote
3answers
116 views

What should be in my business logic class

We are currently having an internal debate on how our business logic classes should be structured. At the moment we structure our business classes like this: public class OrderBL { public void ...
0
votes
0answers
86 views

SQL/HQL in a Play framework controller and Service Layer pattern

I started using the Play Framework a couple of months ago. It "redefines" many conventions from the traditional Java world (like the way of using static methods among other things). I was browsing the ...
0
votes
2answers
169 views

Good design pattern to enable/disable certain functionality based on condition

I am working on a paint type application in android. I got toolbar on left contains tools like undoCut, redoCut, box, frame, cutting, coloring, next, previous etc. I wanted to know what is the best ...
2
votes
2answers
2k views

Low Coupling: Single Responsibility Principle vs Cohesion

I've read several articles on SRP and cohesion, and they seem to contradict each other as far as low coupling is concerned. Articles on cohesion argue that putting closely related responsibilities ...
8
votes
2answers
430 views

Why does 'zip' ignore the dangling tail of the collection?

C#, Scala, Haskell, Lisp and Python have the same zip behaviour: if one collection is longer, the tail is silently ignored. It could be an exception thrown as well, but I didn't heard of any language ...
0
votes
2answers
199 views

Per my design requirements, does this design hierarchy seem reasonable?

Background Construction Note that I am using C# here, but it may not be necessary to provide input to my conceptual questions about design. Consider the following design methodology... I work at a ...
2
votes
1answer
121 views

Are nested private classes considered composition?

Background I am considering a design that includes a public API class containing many nested private classes. I am doing this for the following reasons: Why private nesting? They will have no use ...
6
votes
4answers
274 views

How to separate public and “mostly private” code in C#? (Friend classes, PIMPL pattern, etc.)

Reminder: If you have tips, please remember to put the reason objectively, such as "having two distinct SetInt() functions in the same file violates reader expectations that they'll be overloads, and ...
19
votes
5answers
4k views

Is it okay for a class to use its own public method?

Background I currently have a situation where I have an object that is both transmitted and received by a device. This message has several constructs, as follows: public void ReverseData() public ...
1
vote
0answers
73 views

Guaranteed message sending for messages of different priority for different modules

We have created a message que system using priority messages. The idea behind this is as follows: We have a list of clients. All clients know if (and what kind of priority) messages they have ...
1
vote
2answers
186 views

Software Design, a fitting Design Pattern?

Currently we need to interface with a REST API. The only problem we have implementing this is choosing the right approach. We’ve done this by using Resources – for example a Photo Resource that has ...