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

learn more… | top users | synonyms (1)

16
votes
5answers
3k views

When would polling for events be better than using observer pattern?

Are there scenarios where polling for events would be better than using the observer pattern? I have a fear of using polling and would only start using it if someone gave me a good scenario. All I can ...
16
votes
2answers
4k views

What are the drawbacks to the ActiveRecord pattern?

I'm curious what are the drawbacks to using the ActiveRecord pattern for data access/business objects. The only one I can think of off the top of my head is that it violates the Single Responsibility ...
16
votes
4answers
11k views

Model-View-Presenter implementation thoughts

I'm trying to get a good grasp of how to implement good decoupling between a UI and the model, but I'm having trouble figuring out exactly where to divide the lines. I've been looking at ...
16
votes
10answers
2k views

GoF Design Patterns - which ones do you actually use? [closed]

I'm trying to educate my colleagues in the area of design patterns. Some of the original Gang of Four patterns are a little esoteric, so I'm wondering if there is a sub-group of "essential" patterns ...
16
votes
4answers
4k views

Mediator vs Observer?

Can someone provide me with a canonical answer on the differences between an Observer and a Mediator, and a summary of when you should use one pattern over the other? I am unsure of what kind of ...
16
votes
3answers
976 views

Newbie question about Decorator design pattern

I was reading a programming article and it mentioned the Decorator pattern. I've been programming for awhile but without any kind of formal education or training, but I'm trying to learn about the ...
16
votes
3answers
3k views

How to store prices that have effective dates?

I have a list of products. Each of them is offered by N providers. Each providers quotes us a price for a specific date. That price is effective until that provider decides to set a new price. In ...
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?
15
votes
5answers
922 views

Is this pattern bad? [duplicate]

I notice that when I code I often use a pattern that calls a class method and that method will call a number of private functions in the same class to do the work. The private functions do one thing ...
15
votes
6answers
1k views

Strategies for avoiding SQL in your Controllers… or how many methods should I have in my Models?

So a situation I run into reasonably often is one where my models start to either: Grow into monsters with tons and tons of methods OR Allow you to pass pieces of SQL to them, so that they are ...
15
votes
2answers
4k views

DDD - Does an aggregate root's repository handle saving aggregates?

I am using a DDD-like approach for a greenfield module of an existing application; it's not 100% DDD due to architecture but I'm trying to use some DDD concepts. I have a bounded context (I think ...
15
votes
2answers
1k views

Equivalent of SOLID principles for functional programming

I've found the SOLID principles quite useful when thinking about object-oriented design. Is there a similar / equivalent set of language-agnostic principles tailored for functional programming?
15
votes
4answers
361 views

Is there a specific design strategy that can be applied to solve most chicken-and-egg problems while using immutable objects?

Coming from a OOP background (Java), I'm learning Scala on my own. While I can readily see the advantages of using immutable objects individually, I'm having a hard time seeing how one can design a ...
15
votes
3answers
1k views

Does the state Pattern violate Liskov Substitution Principle?

This image is taken from Applying Domain-Driven Design and Patterns: With Examples in C# and .NET This is the class diagram for the State Pattern where a SalesOrder can have different states during ...
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 ...
14
votes
13answers
3k views

Where is the M in MVC?

I'm trying to refactor my application into MVC, but I'm stuck on the M part. In a database-backed app, the model is implemented in the app code, right? But then, what is in the database -- is that ...
14
votes
4answers
554 views

Is it possible to loosely couple an application to its framework?

Let's say I'm developing a web application. My first choice is to use PHP with Fat-Free Framework (F3) and MVC pattern. Next year, I might decide I want to switch to Zend Framework, or maybe even ...
14
votes
8answers
3k views

Is the GoF book still the one to read? [duplicate]

Possible Duplicate: Is there a canonical book on design patterns? I'd like to read a design patterns book. GoF for sure is the one to read. But after 15 years is it still valid, I mean ...
14
votes
8answers
429 views

When should complexity be removed?

Prematurely introducing complexity by implementing design patterns before they are needed is not good practice. But if you follow all (or even most of) the SOLID principles and use common design ...
14
votes
9answers
3k views

What should a programmer learn first: Algorithms or Design Patterns? [closed]

I have new junior programmers (new graduates) who just joined my team, some of them do not know much about algorithms and design patterns. I am not sure which one should I teach them first?
14
votes
2answers
3k views

What are the main practices and design patterns every .NET guy should know?

In my brief time as a professional programmer I've seen lots of applications written by programmers who's entire education appears to have been reading the first couple of chapters in a .NET 2.0 book. ...
14
votes
3answers
6k views

Static factory vs factory as a singleton

In some of my code, I have a static factory similar to this: public class SomeFactory { // Static class private SomeFactory() {...} public static Foo createFoo() {...} public ...
14
votes
2answers
5k views

Relationship between Repository and Unit of Work

I am going to implement a repository, and I would like to use the UOW pattern since the consumer of the repository could do several operations, and I want to commit them at once. After read several ...
14
votes
3answers
848 views

How can you tell whether to use Composite Pattern or a Tree Structure, or a third implementation?

I have two client types, an "Observer"-type and a "Subject"-type. They're both associated with a hierarchy of groups. The Observer will receive (calendar) data from the groups it is associated with ...
13
votes
8answers
3k views

Does MVC apply only to web

It is almost and instantaneous whenever I talk to developers about Model View Controller (MVC) they say you make a request to a url the server builds a entity (MODEL) and provides you with visual ...
13
votes
9answers
5k views

Are too many if-else statements for validation bad? [duplicate]

From the book Professional Enterprise .Net, which has 5 star rating on Amazon that I am doubting after having a read through. Here is a Borrower class (In C# but it's pretty basic; anyone can ...
13
votes
14answers
5k views

What would be the best real example to explain the usefulness of Inheritance ? [closed]

When trying to explain the concept of Inheritance in OOP, the common example is often the mammals example. IMHO, this is really a bad example, because it will lead the newbies to use this concept the ...
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 ...
13
votes
2answers
2k views

Does the Decorator Pattern exist in the Java IO classes?

For an assignment, I have to find out which of the Gang of Four design pattern the classes java.io.Reader and its subclasses java.io.PushbackReader, java.io.BufferedReader and java.io.FilterReader ...
13
votes
2answers
1k views

What is a 'good number' of exceptions to implement for my library?

I've always wondered how many different exception classes I should implement and throw for various pieces of my software. My particular development is usually C++/C#/Java related, but I believe this ...
13
votes
1answer
589 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 ...
13
votes
4answers
594 views

Proper Model-View-_____ design

I've been reading up about Model View Controller, Model View Presenter, Model View ViewModel, and so on, and generally, the underlying concept seems pretty simple to understand: keep the pretty ...
13
votes
4answers
5k views

success:/failure: blocks vs completion: block

I see two common patterns for blocks in Objective-C. One is a pair of success:/failure: blocks, the other is a single completion: block. For example, lets say I have a task that will return an object ...
13
votes
2answers
1k views

Is “Analysis Patterns: Reusable Object Models” Still A Good Book To Use For Its Subject Matter Today?

Is "Analysis Patterns: Reusable Object Models" by Martin Fowler (published 1996) still a good book to use for the content it covers? Are there other good books that cover the same content? Are there ...
12
votes
7answers
599 views

Should universities put more emphasis on teaching their students about design patterns?

While I've heard about design patterns being mentioned in a few courses at uni, I know of only a single course which actually teaches design patterns. In almost all other areas (algorithms, ...
12
votes
8answers
931 views

Algorithm Vs Design [duplicate]

Possible Duplicate: Is it essential to learn algorithms to be a real programmer? This question is, perhaps, related mostly to web developers who, like myself, code enterprise applications ...
12
votes
3answers
3k views

How to avoid “managers” in my code

I'm currently re-designing my Entity System, for C++, and I have a lot of Managers. In my design, I have these classes, in order to tie my library together. I've heard a lot of bad things when it ...
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 ...
12
votes
4answers
2k views

Does anyone have a specific example of using the Flyweight Pattern?

I have been studying design patterns and came accross the fly weight pattern. I have been trying to see opportunities to use the pattern in my applications but I am having trouble seeing how to use ...
12
votes
4answers
2k views

What is pattern based programming?

Can somebody explain the obsession with patterns and anti-patterns in programming? I ask because I have absolutely no idea what any of the patterns mean. When faced with a programming task I think ...
12
votes
3answers
2k views

Recommended order for learning design patterns? [closed]

I can't help but notice the amount of design patterns that are out there. Does anyone have suggestions on an order I should learn them in? Or should I pick and choose them at random? The only one I ...
12
votes
2answers
838 views

I should have used a factory method instead of a constructor. Can I change that and still be backwards-compatible?

The problem Let's say I have a class called DataSource which provides a ReadData method (and maybe others, but let's keep things simple) to read data from an .mdb file: var source = new ...
12
votes
2answers
396 views

Looking for some OO design advice

I'm developing an app that will be used to open and close valves in an industrial environment, and was thinking of something simple like this:- public static void ValveController { public static ...
12
votes
4answers
731 views

Adding field to the class at runtime - design pattern

Imagine your customer want's to have a possibility to add new property (e.g. color) to product in their eshop in their CMS. Instead of having properties as fields: class Car extends Product { ...
11
votes
7answers
2k views

Name/Fix for Production Code Whose Sole Purpose is to Facilitate Testing? [duplicate]

The linked "duplicate" question is an iffy match at best, because it's asking is pattern X OK (YES/NO) and I'm clearly already in the NO camp, and subsequently asking what is pattern X called ...
11
votes
8answers
558 views

What is a good code practice of when to make a function/method for small repetitive code segments?

Many times throughout writing larger programs I have questioned after how many copy and pastes does it make sense to put the code into a function or method and what is a good rule of thumb? I have ...
11
votes
6answers
1k views

How to Be a Software Engineer?

My problem is kind of weird so please bear with me. I have been working in a start up concerned basically with mobile development since my graduation 2 years ago. I develop apps for iOS but it's not ...
11
votes
11answers
1k views

What are some techniques to teach programmers design patterns? [closed]

I'm in a position where my developers are asking to learn design patterns. So far we have done a book club reading Heads First Design Patterns. During this we worked through examples and talked about ...
11
votes
3answers
583 views

Is using unit tests to tell a story a good idea?

So, I have an authentication module I wrote some time ago. Now I'm seeing the errors of my way and writing unit tests for it. While writing unit tests, I have a hard time coming up with good names and ...
11
votes
7answers
519 views

Introducing design concepts/patterns/principles to co-workers

I've read Joel's article about getting things done when you're a "grunt", several times in fact, but I've never been able to do any of the things it mentions. I work as part of a small development ...