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

learn more… | top users | synonyms (1)

12
votes
2answers
2k views

Differences between Design by Contract and Defensive Programming

Could Designing by Contract (DbC) be a way to program defensively? Is one way of programming better in some cases than the other?
0
votes
4answers
349 views

To which layer does this code belong?

When I say "Revisional Data Model", I mean a data model where information is never lost: Deletes never destroy any rows, and updates always cause an insert somewhere else to preserve a row's previous ...
2
votes
1answer
105 views

Is it OK to pass the concrete client to a method on the concrete strategy?

When using the strategy pattern, is it good practice to pass this to a method on this.strategy? I have a strategy interface with one call, TakeAction. The idea is that TakeAction decides which of ...
5
votes
3answers
735 views

What are the disadvantages of unobtrusive script patterns in web applications?

First of all, is there a name for this as a bona-fide design pattern? Currently I've just been referring to it as "unobtrusive javascript". Here is a brief example of what I am talking about: 1.) Use ...
23
votes
11answers
12k 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 ...
4
votes
3answers
2k views

Is CRTP used much? and why it is/isn't? [closed]

I'm thinking about curiously recurring template pattern. I find it quite useful, and it's pretty well adjustable for many tasks. But I have to admit, I don't see much of CRTP code in the wild. Is it ...
6
votes
2answers
717 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 ...
4
votes
2answers
1k views

What is a good code pattern for single retry then error?

I am writing a routine which has the following form: TRY A IF no success, B IF no success, RETRY A IF no success, throw error It's not trivial to extract either A or B into it's own routine, so ...
1
vote
1answer
145 views

Working with a restful Api; what resources would you like available to start with? [closed]

When working with a web based restful api what resources would you like to work with from the beginning when developing a system against it? Web based documentation? Working example? Simple? ...
1
vote
1answer
666 views

Organizing large Javascript applications - The view layer

Today Javascript application of a relevant size become more and more common, and as the need arises, certain patterns are identified to manage the code complexity. I try to follow good advice, but I ...
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 ...
3
votes
1answer
263 views

What are the relative merits for implementing an Erlang-style “Continuation” pattern in C#

What are the relative merits (or demerits) for implementing an Erlang-style "Continuation" pattern in C#. I'm working on a project that has a large number of Lowest priority threads and I'm wondering ...
10
votes
6answers
918 views

Struggling with the Single Responsibility Principle

Consider this example: I have a website. It allows users to make posts (can be anything) and add tags that describe the post. In the code, I have two classes that represent the post and tags. Lets ...
0
votes
2answers
737 views

Who can change the View in MVC?

I'm working on a thick client graph displaying and manipulation application. I'm trying to apply the MVC pattern to our 3D visualization component. Here is what I have for the Model, View, and ...
5
votes
2answers
1k views

How is the facade pattern different from abstraction layers?

I just read about the facade pattern and found this example where a client (user of a computer) invokes a startComputer() method which calls on all the complex stuff: Source: wikipedia /* Complex ...
1
vote
1answer
637 views

Can the Abstract Factory pattern be considered as a case of polymorphism?

I was looking for a pattern/solution that allows me call a method as a runtime exception in a group of different methods without using Reflection. I've recently become aware of the Abstract Factory ...
4
votes
4answers
2k views

Are there any GUI or user interface design patterns? [closed]

I was curious about GUI design patterns, so I searched and got some information, including a list of UI patterns for the web. This UI patterns website says that: UI Patterns is a growing ...
2
votes
2answers
558 views

Best practice for processing a list of items

I have a list of objects that need to be processed in some way. That way may not be correct for an item and thus raise an exception. In pseudo-code, it would look like: proccessItems (list) error = ...
5
votes
4answers
381 views

Discovering elegant ways of coding

I read this thread on programmers today and thought that looked like a really elegant way of coding. I would like to discover more neat methods of coding. What are the best ways of discovering new ...
2
votes
1answer
234 views

How should I design a correct OO design in case of a Business-logic wide operation

EDIT: Maybe I should ask the question in a different way. in light of ammoQ's comment, I realize that I've done something like suggested which is kind of a fix and it is fine by me. But I still want ...
4
votes
2answers
1k views

“Worker object pool” pattern?

In my application requests are processed by objects of Processor-derived classes, something like CreateItemProcessor or MoveItemToGroupProcessor. Base Processor class implements most of common ...
3
votes
1answer
295 views

How to Implement Restricted Access to Application Features

I'm currently developing a web application, that provides some 'service' to the user. The user will have to select a 'plan' according to which she/he will be allowed to perform application specific ...
11
votes
2answers
5k views

Understanding the bridge design pattern

I do not understand the "bridge" design pattern at all. I have gone through various web sites, but they haven't helped. Can anybody help me in understanding this?
5
votes
2answers
112 views

How to document/verify consistent layering?

I have recently moved to the dark side: I am now a CUSTOMER of software development -- mainly websites. With this new role comes new concerns. As a programmer i know how solid an application ...
6
votes
1answer
1k views

CQRS without using others patterns

I would like to explain CQRS to my team of developers. I just can't figure out how to explain it in the simplest way so they can implement the pattern rapidly without any others frameworks. I've read ...
14
votes
8answers
445 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 ...
2
votes
2answers
235 views

ResourceSerializable: an alternate to ORM and ActiveRecord

A few opinionated reasons I don't like the traditional ORM and ActiveRecord patterns: They work only with a database. Sometimes I'm dealing with objects from an API and other objects from a ...
67
votes
16answers
37k 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 ...
36
votes
8answers
12k 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 ...
20
votes
3answers
12k views

Who should control navigation in an MVVM application?

Example #1: I have a view displayed in my MVVM application (let's use Silverlight for the purposes of the discussion) and I click on a button that should take me to a new page. Example #2: That same ...
25
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-know shortcoming of traditional class hierarchies is that they are bad when it comes to model the real world. As an example, trying to represent animals species with classes. There are actually ...
20
votes
3answers
5k 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 { ...
14
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 ...
10
votes
6answers
1k views

Is it necessary to know and understand design patterns in order to be a professional programmer? [duplicate]

Possible Duplicate: Are design patterns really essential nowadays? Is it necessary have a knowledge and understanding of design patterns for someone to be a professional programmer? Why?
4
votes
2answers
605 views

Age of Design Patterns

When did these design patterns originate? Balking, Builder, Delegation, Facade, Memento. I have looked for days across the net, so if someone points me to a simple google search I may shoot myself. ...
0
votes
2answers
277 views

Inheritance versus Composition in a business application

I have a training management and tracking system, with a high level structure as follows: We have a Role1, e.g. Manager, Shift-boss, miner, etc. and a Candidate, training for that Role. The role has ...
19
votes
5answers
8k views

Is “Mapper” a valid design pattern or is it a variation of the “Factory” pattern?

A common pattern I see is what's known as the Mapper pattern (not to be confused with DataMapper which is something else entirely), which takes as an argument some kind of "raw" data source (e.g. an ...
6
votes
2answers
273 views

Should ActiveRecord-based domain models have visible properties? Why or why not?

Should ActiveRecord-based domain models have visible properties? Why or why not? My experience and studies have always lead me to believe that object properties should always be protected, and that ...
7
votes
2answers
466 views

Help me classify this type of software architecture

I read some books about software architecture as we are using it in our project but I can't classify the architecture properly. It's some kind of Enterprise Architecture, but what exactly... SOA, ESB ...
5
votes
4answers
514 views

Where does form processing belong in an MVC application?

I found this question on stack overflow and I have a question about one of the answers: In Zend Framework, forms are typically objects with decorators, but usually (I thought) processing is done ...
11
votes
8answers
998 views

How 'simple' is a real KISS solution? [closed]

I confess: I have a problem to "Keep It Simple and Short" most of the time because trying to make it according to the books I have read, design-patterns I have heard etc. gives me such an enthusiasm ...
3
votes
2answers
1k views

How do you organize an ASP.NET MVC 3 application with potentially hundreds of views but with only a few entry points?

Assumptions: Minimalist ASP.NET MVC 3 application for sending emails where the view represents the contents of an email. Over 500+ email types. I would NOT like to have 500+ actions in my controller ...
2
votes
3answers
541 views

RFC: Extending the MVC Design Pattern

I've been using the MVC pattern in my applications for years (with full separation of the controller from its views). Having to implement several hundred views to represent a little over 100 model's ...
2
votes
2answers
679 views

Translating objects from one type to a another

I am working on a server-client app in c# and need to send an object from the client to the server via WCF. For simplicity I will call it WorkingClass as it is what does the work. public class ...
6
votes
2answers
456 views

Is there a standard, formal name for an object or class that behaves as if it is a given object?

I have an app in Django that expects to get a record with the fields email, first_name, and last_name. However, sometimes I want to be able to send it something that isn't actually a record but ...
35
votes
5answers
10k 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 ...
3
votes
2answers
748 views

Which GOF design patterns work well with TDD, and which do not?

The GOF Design Patterns book rarely mentions the test-ability of each pattern. I'm aware that there are patterns such as Singleton that would lead to code for which it is difficult to write unit ...
-11
votes
5answers
1k views

Are version control systems a form of design pattern? [closed]

I'm having some trouble understanding what a design pattern is and isn't, particularly with respect to version control systems like CVS and Git. Is "push, pop, stack" a "design pattern"? If yes, is ...
1
vote
2answers
524 views

Am I using Factory and Impl classes properly?

In my 2d destruction derby simulator I have a CargoTruck class and CargoTruckImpl that implement an interface called Truck. CargoTruck has a reference to CargoTruckImpl which is returned through the ...
10
votes
9answers
1k views

Is this an anti-pattern?

I've seen this a lot in our legacy system at work - functions that go something like this: bool todo = false; if(cond1) { ... // lots of code here if(cond2) todo = true; ... // some other ...