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

learn more… | top users | synonyms (1)

24
votes
7answers
15k views

Self-Executing Anonymous Function vs Prototype

In Javascript there are a few clearly prominent techniques for create and manage classes/namespaces in javascript. I am curious what situations warrant using one technique vs. the other. I want to ...
2
votes
1answer
519 views

Most frequently used design patterns in refactoring (my example) [closed]

I've been doing quite a lot of refactoring of C++ and C# code recently, and found that 90% of the patterns I use are: Template method Factory Singleton Are these generally the most commonly used ...
0
votes
1answer
562 views

Wrapping a 3rd party API - Gateway Pattern connections

Given a 3rd party API with a very cumbersome object with many different responsibilities-- we decide to wrap using small, manageable, single-responsibility objects. This is the gateway pattern (I ...
3
votes
2answers
773 views

Adding more responsibilities to Activities in a flexible way

I am considering how I can add tasks to Android Activities in a flexible way. I can only use implementation inheritance for one thing in Java and I would like to use it, if I use it at all, for ...
3
votes
1answer
633 views

What's a good notation for showing MVC interactions?

I'm developing various websites and functionality to cater to various different use-cases up in Django. Is there a good notation for showing what behaviour is at each stage, e.g., swimlanes. I use ...
126
votes
10answers
88k views

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 ...
21
votes
11answers
1k views

Choose code design effort or laziness in Bank world

I've worked for two years in a great Investment Bank. I made some technical projects with the desire of creating code the most optimized, respecting the adapted good design patterns, SOLID principle, ...
5
votes
5answers
516 views

I need some counter-points to counter the argument of why NOT to use M-V-P

I whipped up a demo on Friday before the holiday weekend of using the Model-View-Presenter pattern (the "Passive View" version, I believe) that I want to show to my co-workers this week as an example ...
4
votes
5answers
1k views

Are design patterns independent of programming languages?

I have been recently working on Objective C and came across use of Delegate pattern. I had seen most of the common patterns theoretically in Java, thanks to the Head First book. But at times looking ...
1
vote
3answers
380 views

Is the “exposer (hack) pattern” a newly identified pattern or does it have another name?

EDITED FOR CLARIFICATION In the past, I have seen a whole manner of resolutions and fudges. Some really stand out. One particular resolution that I initially thought of as a fudge possibly deserves a ...
7
votes
2answers
366 views

where can I find an overview of known “multithreading systems architectures” design patterns? [closed]

Using C#, I have been doing multithreaded development for about 5 years, and consider myself quite proficient (I wrote my own lock-free queue and task parallel framework before Microsoft made TPF). ...
2
votes
1answer
1k views

How do you do to create the ViewModel part of your MVVM designs?

Sometimes, when I plan to create a program using this architectural pattern, I've got a lot of difficulties when I'm in the View Model phase. I'm using WAF Framework to develop this architectural ...
2
votes
2answers
141 views

Pattern for user interaction and confirmation

Suppose a FileWriter class that needs validation that it will not erase a file already present, if one is found. It would have two functions: public bool FileExists(string filePath) //... public bool ...
0
votes
3answers
111 views

Should I decompress zips before I archive?

I am writing a small personal archiving tool. I frequently work with a lot of client databases for short periods, what my tool will do is in overnight batch jobs it will detach the database and zip up ...
7
votes
3answers
952 views

Data replication patterns / algorithms

I have a series of systems that need to be distributed to a variable number of nodes (at least two, but more likely 8 - 10). For performance reasons, any one piece of state needs to be maintained in ...
18
votes
9answers
5k views

How important are design patterns in programming?

I'm a university student and I've just started learning about design patterns and im struggling to understand the purpose of them. I have tried researching them but all the resources I have found seem ...
3
votes
1answer
213 views

Exposing warnings\errors from data objects (that are also list returned)

I'm exposing Data objects via service oriented assembly (which on future usages might become a WCF service). The data object is tree designed, as well as formed from allot of properties.Moreover, ...
1
vote
1answer
233 views

Pattern for a web application

I'm developing a web application for a university project. My professor wants we to use a multi-tier architecture (Client, Web, Business and Data tiers) with EJB. For the Web and Business I have ...
7
votes
1answer
4k views

Observer pattern; knowing *what* changed?

I've created two abstract classes Subject and Observer that define a classic Observer pattern interface. I derive from them to implement the Observer pattern. An observer might look like this: void ...
13
votes
2answers
3k 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
5answers
440 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
112 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
865 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 ...
27
votes
11answers
18k 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 ...
5
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 ...
7
votes
3answers
1k 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 ...
5
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
722 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
292 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
1k 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
928 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 ...
6
votes
2answers
2k 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
722 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
3k 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
650 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
393 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
249 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
2k 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
314 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 ...
13
votes
2answers
6k 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
115 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
484 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
260 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 ...
74
votes
16answers
57k 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 ...
42
votes
8answers
14k 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 ...
26
votes
3answers
16k 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 ...
24
votes
3answers
7k 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 { ...