A design pattern is a general reusable solution to a commonly occurring problem in software design.
269
votes
13answers
78k views
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, ...
171
votes
18answers
65k views
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 ...
115
votes
17answers
21k views
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 ...
114
votes
10answers
20k views
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 ...
109
votes
14answers
18k views
“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 ...
93
votes
10answers
48k views
What is MVC, really? [closed]
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 ...
85
votes
21answers
7k views
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 ...
77
votes
14answers
21k views
Do I need to use an interface when only one class will ever implement it?
Isn't the whole point of an interface to for multiple classes to adhere to a set of rules and implementations?
71
votes
8answers
10k views
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 ...
70
votes
14answers
4k views
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 ...
69
votes
10answers
7k views
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 ...
66
votes
16answers
33k views
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 ...
60
votes
3answers
10k views
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 ...
58
votes
11answers
5k views
“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 ...
58
votes
10answers
5k views
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 ...
53
votes
2answers
6k views
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 ...
50
votes
2answers
6k views
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 ...
50
votes
5answers
10k views
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 ...
49
votes
4answers
11k views
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?
47
votes
6answers
40k views
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 ...
42
votes
5answers
3k views
When is Singleton appropriate?
Some hold that the Singleton Pattern is always an anti-pattern. What do you think?
40
votes
15answers
16k views
When should I use—and not use—design patterns? [duplicate]
In a previous question of mine on Stack Overflow, FredOverflow mentioned in the comments:
Note that patterns do not magically improve the quality of your code.
and
Any measure of quality ...
37
votes
6answers
10k views
Where are all the functional programming design patterns?
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 ...
36
votes
11answers
5k views
Are error variables an anti-pattern or good design?
In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
36
votes
11answers
4k views
Constructor-only subclasses: Is this an anti-pattern?
I was having a discussion with a co-worker, and we ended up having conflicting intuitions about the purpose of subclassing. My intuition is that if a primary function of a subclass is to express a ...
36
votes
2answers
6k views
What is the purpose of NaN boxing?
Reading 21st Century C I arrived at chapter 6 at the section "Marking Exceptional Numeric Values with NaNs", where it explains the use of the bits in the mantissa to store some arbitrary bit patterns, ...
35
votes
13answers
6k views
Design patterns - do you use them?
Being an IT student, I was recently given some overview about design patterns by one of our teachers. I understood what they are for, but some aspects still keep bugging me.
Are they really used by ...
35
votes
8answers
11k views
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 ...
35
votes
11answers
4k views
Ensure that each class has only one responsibility, why?
According to Microsoft documentation, the Wikipedia SOLID principe article, or most IT architects we must ensure that each class has only one responsibility. I would like to know why, because if ...
35
votes
6answers
16k views
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 ...
35
votes
8answers
12k views
Return magic value, throw exception or return false on failure?
I sometimes end up having to write a method or property for a class library for which it is not exceptional to have no real answer, but a failure. Something cannot be determined, is not available, not ...
34
votes
5answers
9k views
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 ...
34
votes
5answers
7k views
What are the downfalls of MVC? [closed]
I've been using MVC/MV* since I started actually organizing my code years ago. I've been using it so long that I can't even think of any other way to structure my code and every job I've had after ...
33
votes
8answers
3k views
Is OOP becoming easier or harder?
When the concepts of Object Oriented Programming were introduced to programmers years back it looks interesting and programming was cleaner. OOP was like this
Stock stock = new Stock();
...
33
votes
4answers
6k views
The importance of Design Patterns with Javascript, NodeJs et al
With Javascript appearing to be the ubiquitous programming language of the web over the next few years, new frameworks popping up every five minutes and event driven programming taking a lead both ...
32
votes
9answers
6k views
When writing object-oriented code, should I always be following a design pattern?
Is there a conceivable design pattern for any object-oriented program? I ask this because recently I saw an implementation of a Door class with a Lock. It was part of a test and the answer said that ...
32
votes
11answers
5k views
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 ...
32
votes
10answers
4k views
Difference between Idiom and Design Pattern?
What is the difference between idiom and design-pattern? It seems that these terminologies overlap somewhere; where exactly, I don't know. Are they interchangeable? When should I use what?
Here is a ...
32
votes
8answers
9k views
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 ...
32
votes
9answers
1k views
How do I overcome paralysis by analysis when coding?
When I start a new project, I often times immediately start thinking about the details of implementation. "Where am I gonna put the DataBaseHandler? How should I use it? Should classes that want to ...
31
votes
9answers
4k views
Should we avoid using design patterns in constantly changing projects?
A friend of mine is working for a small company on a project every developer would hate: he's pressured to release as quickly as possible, he's the only one who seem to care about technical debt, the ...
31
votes
11answers
4k views
Is the 'C' in MVC really necessary?
I understand the role of the model and view in the Model-View-Controller pattern, but I have a hard time understanding why a controller is necessary.
Let's assume we're creating a chess program using ...
30
votes
7answers
6k views
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. ...
30
votes
7answers
2k views
Design Patterns for Javascript [duplicate]
A lot of web frameworks have a MVC-style layout to code and approaching problems. What are some good similar paradigms for JavaScript? I'm already using a framework (jQuery) and unobtrusive js, but ...
30
votes
2answers
13k views
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 ...
29
votes
1answer
6k views
What is the difference between the factory pattern and abstract factory?
Having finally begun seriously trying to learn some basic patterns (very late in the career, but that's a different story), I'm trying to get my head around the differences between the Factory Pattern ...
28
votes
6answers
5k views
LSP vs OCP / Liskov Substitution VS Open Close
I am trying to understand the SOLID principles of OOP and I've come to the conclusion that LSP and OCP have some similarities (if not to say more).
the open/closed principle states "software ...
28
votes
4answers
31k views
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?
27
votes
11answers
2k views
Are design patterns generally a force for good or bad? [closed]
I've heard it argued that design patterns are the best thing since sliced bread. I've also heard it argued that design patterns tend to exacerbate "Second System Syndrome," that they are massively ...
27
votes
11answers
2k views
Well designed / high-quality open source software [closed]
I'm taking a software design class where I should choose an open source software to analyze from the Software Design point of view.
It has to be a big project: not less then 100,000 lines of code.
I ...