Skip to main content

Questions tagged [design-patterns]

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

Filter by
Sorted by
Tagged with
618 votes
13 answers

So Singletons are bad, then what?

There has been a lot of discussion lately about the problems with using (and overusing) Singletons. I've been one of those people earlier in my career too. I can see what the problem is now, and yet, ...
Bobby Tables's user avatar
  • 20.6k
456 votes
12 answers

How accurate is "Business logic should be in a service, not in a model"?

Situation Earlier this evening I gave an answer to a question on StackOverflow. The question: Editing of an existing object should be done in repository layer or in service? For example if ...
Jeroen Vannevel's user avatar
431 votes
18 answers

Why is Global State so Evil?

Before we start this, let me say I'm well aware of the concepts of Abstraction and Dependency Injection. I don't need my eyes opened here. Well, most of us say, (too) many times without really ...
Madara's Ghost's user avatar
333 votes
16 answers

Do I need to use an interface when only one class will ever implement it?

Isn't the whole point of an interface that multiple classes adhere to a set of rules and implementations?
Lamin Sanneh's user avatar
  • 4,045
241 votes
10 answers

Is there a name for the (anti- ) pattern of passing parameters that will only be used several levels deep in the call chain?

I was trying to find alternatives to the use of global variable in some legacy code. But this question is not about the technical alternatives, I'm mainly concerned about the terminology. The ...
RubenLaguna's user avatar
  • 1,912
225 votes
11 answers

Why do we need so many classes in design patterns?

I am junior developer among seniors and am struggling a lot with understanding their thinking, reasoning. I am reading Domain-Driven Design (DDD) and can't understand why we need to create so many ...
user1318496's user avatar
  • 1,797
222 votes
10 answers

What is MVC, really?

As a serious programmer, how do you answer the question What is MVC? In my mind, MVC is sort of a nebulous topic — and because of that, if your audience is a learner, then you're free to ...
Nicole's user avatar
  • 28.2k
219 votes
16 answers

My boss asks me to stop writing small functions and do everything in the same loop

I have read a book called Clean Code by Robert C. Martin. In this book I've seen many methods to clean up code like writing small functions, choosing names carefully, etc. It seems by far the most ...
GitCommit Victor B.'s user avatar
218 votes
18 answers

How can one manage thousands of IF...THEN...ELSE rules?

I am considering building an application, which, at its core, would consist of thousands of if...then...else statements. The purpose of the application is to be able to predict how cows move around in ...
217 votes
14 answers

"Never do in code what you can get the SQL server to do well for you" - Is this a recipe for a bad design?

It's an idea I've heard repeated in a handful of places. Some more or less acknowledging that once trying to solve a problem purely in SQL exceeds a certain level of complexity you should indeed be ...
206 votes
4 answers

What is an Anti-Corruption layer, and how is it used?

I'm trying to figure out what the Anti-Corruption layer really means. I know that it's a way to transition/work around legacy code or bad APIs. What I don't understand is how it works and what makes ...
knownasilya's user avatar
  • 3,234
191 votes
9 answers

Why should I use a factory class instead of direct object construction?

I have seen the history of several С# and Java class library projects on GitHub and CodePlex, and I see a trend of switching to factory classes as opposed to direct object instantiation. Why should I ...
rufanov's user avatar
  • 1,963
179 votes
6 answers

What is the point of using DTO (Data Transfer Objects)?

What is the point of using DTO and is it an out dated concept? I use POJOs in the view layer to transfer and persist data. Can these POJOs be considered as an alternative to DTOs?
Vinoth Kumar C M's user avatar
169 votes
18 answers

Is it better to return NULL or empty values from functions/methods where the return value is not present?

I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take ...
P B's user avatar
  • 2,379
168 votes
8 answers

Criticism and disadvantages of dependency injection

Dependency injection (DI) is a well known and fashionable pattern. Most of engineers know its advantages, like: Making isolation in unit testing possible/easy Explicitly defining dependencies of a ...
Arkadiusz Kałkus's user avatar
167 votes
10 answers

When is it not appropriate to use the dependency injection pattern?

Since learning (and loving) automated testing I have found myself using the dependency injection pattern in almost every project. Is it always appropriate to use this pattern when working with ...
Tom Squires's user avatar
  • 17.8k
153 votes
14 answers

Did the Gang of Four thoroughly explore "Pattern Space"?

Ever since I first learned about the Gang of Four (GoF) design patterns, at least 10 years ago, I am having the impression that these 23 patterns should be only a small sample of something much larger ...
Frank Puffer's user avatar
  • 6,439
148 votes
6 answers

What is the point of having every service class have an interface? [duplicate]

At the company I work at, every service class has a corresponding interface. Is this necessary? Notes: Most of these interfaces are only used by a single class We are not creating any sort of ...
Bob Roberts's user avatar
  • 1,807
139 votes
13 answers

Are design patterns frowned upon?

I had a discussion with one of our senior developers who's been in the business for 20 years. He's pretty well known in Ontario for a blog he writes. The strange thing is what he told me: he said ...
Igneous01's user avatar
  • 2,333
124 votes
9 answers

Are design patterns really essential nowadays?

I was reading "Coders at Work" and have faced the fact that some of the professionals interviewed in the book are not so enthusiastic about design patterns. I think that there are 2 main reasons for ...
Sergey's user avatar
  • 2,703
115 votes
17 answers

Why should 'boneheaded' exceptions not be caught, especially in server code?

I am confused because in quite a few places I've already read that the so-called 'boneheaded' exceptions (ones that result from bugs in code) are not supposed to be caught. Instead, they must be ...
gaazkam's user avatar
  • 4,469
108 votes
8 answers

Are there any design patterns that are unnecessary in dynamic languages like Python?

I've started reading the design pattern book by the GoF. Some patterns seem very similar with only minor conceptual differences. Do you think out of the many patterns some are unnecessary in a ...
Gere's user avatar
  • 2,201
103 votes
2 answers

What is the "Free Monad + Interpreter" pattern?

I've seen people talking about Free Monad with Interpreter, particularly in the context of data-access. What is this pattern? When might I want to use it? How does it work, and how would I implement ...
Benjamin Hodgson's user avatar
94 votes
4 answers

Is it bad practice that a controller calls a repository instead of a service?

Is it bad practice that a controller calls a repository instead of a service? To explain more: I figure out that in good design controllers call services and services use repositories. But sometimes ...
mohsenJsh's user avatar
  • 1,315
88 votes
6 answers

Where are all the functional programming design patterns? [closed]

OO programming literature is full of design patterns. Most books on object oriented programming dedicate a chapter or two to design patterns like factories and decorators. So what are the equivalent ...
user avatar
86 votes
22 answers

Is OOP hard because it is not natural?

One can often hear that OOP naturally corresponds to the way people think about the world. But I would strongly disagree with this statement: We (or at least I) conceptualize the world in terms of ...
82 votes
14 answers

What should take precedence: YAGNI or Good Design?

At which point should YAGNI take precedence against good coding practices and vice versa? I'm working on a project at work and want to slowly introduce good code standards to my co-workers (currently ...
Wayne Molina's user avatar
  • 15.7k
82 votes
3 answers

What are DRY, KISS, SOLID, etc. classified as?

Is something like DRY a design pattern, a methodology, or something in between? They do not have specific implementations that could neccessarily be demonstrated(even if you can easily demonstrate a ...
user avatar
80 votes
2 answers

Are there any OO-principles that are practically applicable for Javascript?

Javascript is a prototype-based object oriented language but can become class-based in a variety of ways, either by: Writing the functions to be used as classes by yourself Use a nifty class system ...
Spoike's user avatar
  • 14.8k
78 votes
5 answers

What is the "Fix Everything" design pattern?

In this 2003 article by Stephen Figgins on, Bram Cohen's BitTorrent is described as using the "Fix Everything" design pattern. A less common approach that both makes BitTorrent ...
Aaron Hall's user avatar
  • 5,943
78 votes
7 answers

Why should I use an MVC pattern?

It seems everyone doing web applications nowadays wants to use MVC for everything. I find it hard to convince myself to use this pattern, however. I understand the general idea is to separate the ...
Billy ONeal's user avatar
  • 8,073
77 votes
10 answers

Non-OOP Design Patterns? [closed]

I have only heard the term "design pattern" being used for object oriented code, and the GoF patterns include only OOP design patterns, but design patterns are elegant solutions for commonly occuring ...
Anto's user avatar
  • 11.2k
76 votes
5 answers

What are the benefits of using Dependency Injection and IoC Containers?

I'm planning to do a talk on Dependency Injection and IoC Containers, and I'm looking for some good arguments for using it. What are the most important benefits of using this technique, and these ...
Andy Lowry's user avatar
  • 2,402
75 votes
7 answers

What is a helper? Is it a design pattern? Is it an algorithm?

Maybe a little tongue-in-cheek, but as I can't find this answer anywhere through Google, so to ensure Software Engineering has the answer: What is a helper? I have seen the name being used ...
Aaron Hall's user avatar
  • 5,943
72 votes
7 answers

How essential is it to make a service layer?

I started building an app in 3 layers (DAL, BL, UI) [it mainly handles CRM, some sales reports and inventory]. A colleague told me that I must move to service layer pattern, that developers came to ...
BornToCode's user avatar
  • 1,273
72 votes
5 answers

When is Singleton appropriate? [duplicate]

There is a widely accepted opinion that Singleton is an anti-pattern. As usual, there are always exceptions to the rule. Can you explain why Singleton is a bad choice in general and give an example of ...
Fishtoaster's user avatar
  • 25.9k
70 votes
12 answers

"Everything is a Map", am I doing this right?

I watched Stuart Sierra's talk "Thinking In Data" and took one of the ideas from it as a design principle in this game I'm making. The difference is he's working in Clojure and I'm working in ...
Daniel Kaplan's user avatar
68 votes
12 answers

Is this a decent use-case for goto in C?

I really hesitate to ask this, because I don't want to "solicit debate, arguments, polling, or extended discussion" but I'm new to C and want to gain more insight into common patterns used in the ...
Robz's user avatar
  • 1,633
68 votes
5 answers

What is inversion of control, and when should I use it?

I am designing a new system and I want to know what inversion of control (IOC) is, and more importantly, when to use it. Does it have to be implemented with interfaces or can be done with classes?
Jedi Master Spooky's user avatar
67 votes
7 answers

Is dependency injection essential for unit testing?

Is using dependency injection (DI) essential for unit testing? I can't think of another alternative for isolating code so it can be tested. Also, all the examples I have ever seen use this pattern. ...
Tom Squires's user avatar
  • 17.8k
66 votes
8 answers

Is ORM an Anti-Pattern? [closed]

I had a very stimulating and interessting discussion with a colleague about ORM and its pros and cons. In my opinion, an ORM is useful only in the rarest cases. At least in my experience. But I don't ...
derphil's user avatar
  • 869
66 votes
6 answers

Is an event loop just a for/while loop with optimized polling?

I'm trying to understand what an event loop is. Often the explanation is that in an event loop, you do something until you're notified that an event has occurred. You then handle the event and ...
TheMeaningfulEngineer's user avatar
64 votes
10 answers

Do you generally send objects or their member variables into functions?

Which is generally accepted practice between these two cases: function insertIntoDatabase(Account account, Otherthing thing) { database.insertMethod(account.getId(), thing.getId(), thing....
AJJ's user avatar
  • 2,998
63 votes
6 answers

Is object pooling a deprecated technique?

I am very familiar with the concept of object pooling and I always try to use it as much as possible. Additionally I always thought that object pooling is the standard norm as I have observed that ...
user10326's user avatar
  • 1,830
62 votes
2 answers

Best practice/Patterns for two way data synchronisation

Quite often in my work the idea of 2-way data synchronisation between database systems crops up. The classic example is two slightly different CRM systems (say, Raiser's Edge and Salesforce) and the ...
codeulike's user avatar
  • 809
61 votes
11 answers

Are utility classes with nothing but static members an anti-pattern in C++?

The question Where should I put functions that are not related to a class has sparked some debate over whether it makes sense in C++ to combine utility functions in a class or just have them exist as ...
PersonalNexus's user avatar
61 votes
8 answers

MVC Architecture -- How many Controllers do I need?

I have been coding for a while, but mostly scripts and simple applications. I've moved into a new role where it is all about developing Web Apps and using a proper MVC architecture, so I am ...
Jeff's user avatar
  • 1,844
60 votes
2 answers

Communication between nested directives

There seem to be quite a few ways of communicating between directives. Say you have nested directives, where the inner directives must communicate something to the outer (e.g. it's been chosen by the ...
Michal Charemza's user avatar
59 votes
2 answers

Is performance the only reason not to use SignalR (websockets) entirely in lieu of a traditional REST API?

I have used SignalR to achieve real-time messaging functionality in several of my projects. It seems to work reliably and is very easy to learn to use. The temptation, at least for me, is to abandon ...
tacos_tacos_tacos's user avatar
58 votes
8 answers

How do I ensure that interface implementations are implemented in the manner I expected?

Let's say there is a member SomeMethod in an interface ISomeInterface as follows: public interface ISomeInterface { int SomeMethod(string a); } For the purposes of my program, all consumers of ...
user4779's user avatar
  • 929

2 3 4 5