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

learn more… | top users | synonyms (1)

62
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 ...
51
votes
2answers
5k 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 ...
41
votes
5answers
3k views

When is Singleton appropriate?

Some hold that the Singleton Pattern is always an anti-pattern. What do you think?
104
votes
17answers
17k 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 ...
72
votes
14answers
19k 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?
250
votes
13answers
69k 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, ...
57
votes
10answers
4k 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 ...
19
votes
11answers
10k views

Is there a canonical book on design patterns? [closed]

I am interested in learning design patterns and would like to know what are considered top tier books in learning this subject. Is there a book out there that's the de-facto standard for describing ...
29
votes
1answer
5k 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 ...
6
votes
6answers
1k views

Should I extract specific functionality into a function and why?

I have a large method which does 3 tasks, each of them can be extracted into a separate function. If I'll make an additional functions for each of that tasks, will it make my code better or worse and ...
52
votes
3answers
8k 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 ...
105
votes
14answers
14k 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 ...
32
votes
6answers
13k 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 ...
4
votes
2answers
1k views

Choosing the right Design Pattern

I've always recognized the importance of utilizing design patterns. I'm curious as to how other developers go about choosing the most appropriate one. Do you use a series of characteristics (like a ...
86
votes
10answers
40k 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 ...
31
votes
8answers
10k 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 ...
44
votes
6answers
35k 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 ...
21
votes
10answers
5k views

To design pattern, or not to design pattern [duplicate]

Design patterns are good, but complex. Should we use them in small projects? Implementing design patterns needs more sophisticated developers, which in turn raises project costs. On the other hand, ...
15
votes
7answers
2k views

What if I will not use Software Design Patterns? [closed]

What kind of problems may I face, if I won't use Software Design Patterns? Can you tell me about the problems of approaching the design using standard object-oriented techniques?
13
votes
5answers
6k views

What is the difference between all-static-methods and applying a singleton pattern?

I am making a database to store information about the users of my website (I am using stuts2 and hence Java EE technology). For the database I'll be making a DBManager. Should I apply singleton ...
25
votes
4answers
25k 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?
33
votes
8answers
10k 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 ...
21
votes
6answers
1k views

How do I prevent unknowningly duplicating code?

I work on a rather large code base. Hundreds of classes, tons of different files, lots of functionality, takes more than 15 minutes to pull down a fresh copy, etc. A big problem with such a large ...
34
votes
5answers
8k 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 ...
25
votes
7answers
2k views

The Singleton Pattern [duplicate]

Possible Duplicate: When is Singleton appropriate? I am a new programmer (4 months into my first job) and have recently taken an interest in design patterns. One that I have used recently ...
15
votes
3answers
462 views

Learning about design [closed]

How do you improve your ability to design your applications? Where do you get your design ideas from? (I am asking about code design - not about a specific language and not about visual appeal). When ...
9
votes
4answers
808 views

Rails: Law of Demeter Confusion

I am reading a book called Rails AntiPatterns and they talk about using delegation to to avoid breaking the Law of Demeter. Here is their prime example: They believe that calling something like this ...
17
votes
11answers
1k views

Why are we supposed to use short functions to sectionalize our code? [duplicate]

I've seen an increasing trend in the programming world saying that it is good practice to separate code blocks into their own functions. Obviously, if that code block is reusable, you should do that. ...
3
votes
2answers
1k views

Alternative to “inheritance versus composition?” [duplicate]

Possible Duplicate: Where does this concept of “favor composition over inheritance” come from? I have colleagues at work who claim that "Inheritance is an anti-pattern" and want to use ...
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 ...
83
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 ...
40
votes
15answers
14k 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 ...
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 ...
16
votes
2answers
10k views

Separating data access in ASP.NET MVC

I want to make sure I'm following industry standards and best practices with my first real crack at MVC. In this case, it's ASP.NET MVC, using C#. I will be using Entity Framework 4.1 for my model, ...
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 ...
7
votes
2answers
7k views

.NET MVC project architecture / layering

When planning the architecture for a mid-large scale MVC web application how do you implement the layers to be as decoupled as possible and easy to test? (basically follow best practices) Let's say ...
19
votes
3answers
4k views

Where we should put validation for domain model

I still looking best practice for domain model validation. Is that good to put the validation in constructor of domain model ? my domain model validation example as follows: public class Order { ...
17
votes
2answers
5k views

Alternative patterns for web development? (non-MVC)

Recently I've been reading some blog posts regarding MVC and how it doesn't fit the web. I've learned about alternative patterns like the RMR Architecture. I'm curious what other patterns people are ...
23
votes
4answers
4k views

Why was dependency injection pattern not included in the Gang of four?

Why was the dependency injection pattern not incluided in the gang of four? Did GOF pre-date widespread automated testing? Is dependency injection now considered a core pattern?
9
votes
4answers
655 views

Recommend a design pattern/approach to exposing/tolerating/recovering from system errors, Exception handling (e.g.s in Java, C++, Perl, PHP)

Can you recommend a design pattern/approach to exposing/tolerating/recovering from system errors, Exception handling (Java, C++, Perl, PHP)? Some errors need to be reported. Some errors can be ...
8
votes
6answers
929 views

What are the practical ways to implement the SRP?

Simply what are the practical techniques people use to check if a class violates the single responsibility principle? I know that a class should have only one reason to change, but that sentence is ...
12
votes
4answers
928 views

How to determine whether Design Pattern is implemented correctly?

I am successfully able to scale all my old applications which were not using documented Design Patterns. Whatever pattern it is I don't know. To a large extent, I only felt a need to use simple OOP ...
10
votes
4answers
2k views

In MVC, can/should basic data retrieval from the Model be done in the View?

Given the concept of 'skinny controllers, fat models' and the general acceptance that Views can directly call on Models when requiring data for output, should one consider handling the 'get and ...
9
votes
4answers
1k views

How does thinking on design patterns and OOP practices change in dynamic and weakly-typed languages?

There is a fairly helpful question already along these lines ("Non-OOP Design Patterns?"), but I am more curious about a transitional point of view for someone just getting started with dynamic and ...
21
votes
6answers
3k views

How much business logic should be allowed to exist in the controller layer?

Sometimes we have some business logic represented in the controller code of our applications. This is usually logic that differentiates what methods to call from the model and/or what arguments to ...
10
votes
4answers
2k views

How to determine if class meets single responsibility principle?

Single Responsibility Principle is based on high cohesion principle. The difference between the two is that highly cohesive classes feature a set of responsibilities that are strongly related, while ...
7
votes
3answers
2k views

Design pattern for window management in a Java Swing app

I've just started creating my very first little Java Swing app. When the program opens, it brings up a single, simple window with a label and a couple buttons. Clicking one of those buttons is ...
10
votes
3answers
773 views

Dependency Inversion Principle: How to define “high-level policy” and “low-level detail” to other people?

I am trying to explain the dependency inversion principle to my (mostly junior) colleagues. How can we define which one is the "high-level policy" and which one is the "low-level detail" in a ...
5
votes
3answers
1k views

How to create a manager class without global variables nor singletons?

I would like to implement some kind of manager class in my application. It will be in charge of loading textures, processing them, distributing them etc... At first, I wanted to make a global ...
4
votes
2answers
932 views

How does MVC work with the principle “Tell, Don't ask”?

Procedural code gets information then makes decisions. Object-oriented code tells objects to do things. — Alec Sharp So, when a view wants to display some information that is suppose to be ...