design-patterns

Pattern for saving and writing to different file formats

Is there a pattern that is good to use when saving and loading different file formats? For example, I have a complicated class hierarchy for the document, but I want to support a few different file formats. I thought about the Strategy pattern, but I'm not convinced because of the need to access every part of the object in order to sav...

Design Pattern for multithreaded observers

In a digital signal acquisition system, often data is pushed into an observer in the system by one thread. example from Wikipedia/Observer_pattern: foreach (IObserver observer in observers) observer.Update(message); When e.g. a user action from e.g. a GUI-thread requires the data to stop flowing, you want to break the subject-o...

How do you know when to use design patterns?

Anyone can read the GoF book to learn what design patterns are and how to use them, but what is the process for figuring out when a design pattern solves a problem? Does the knowledge of the pattern drive the design, or is there a way to figure out how a pattern can be used to change a design? In other words, are there patterns for Patt...

What design pattern do you use the most?

I'm interested in understanding what design patterns people find themselves using often. Hopefully this list will help other recognize common scenarios and the associated design pattern that can be used to solve them. Please describe a common problem you find yourself solving and the design pattern(s) you use to solve it. Links to blo...

Singleton: How should it be used

Edit: From another question I provided an answer that has links to a lot of questions/answers about singeltons: More info about singletons here: So I have read the thread Singletons: good design or a crutch? And the argument still rages. I see Singletons as a Design Pattern (good and bad). The problem with Singleton is not the Patte...

What's wrong with singleton?

Do not waste your time with this question. Follow up to: http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons Please feel free to bitch on Singleton. Inappropriate usage of Singleton may cause lot of paint. What kind of problem do you experienced with singleton? What is common misuse of this pattern? After som...

Some sort of creational pattern needed in C#

I have the following type : // incomplete class definition public class Person { private string name; public string Name { get { return this.name; } } } I want this type to be created and updated with some sort of dedicated controller/builder, but I want it to remain read-only for other types. This object als...

When do transactions become more of a burden than a benefit?

Transactional programming is, in this day and age, a staple in modern development. Concurrency and fault-tolerance are critical to an applications longevity and, rightly so, transactional logic has become easy to implement. As applications grow though, it seems that transactional code tends to become more and more burdensome on the scala...

Is There Any Advantage in Passing a UI wrapper to a view

Most of the MVC samples I have seen pass an instance of the view to the controller like this public class View { Controller controller = new Controller(this); } Is there any advantage to passing a class which provides access to just the the properties and events the controller is interested in, like this: public class UIWrappe...

Lua Patterns,Tips and Tricks

This is a Tips & Tricks question with the purpose of letting people accumulate their patterns, tips and tricks for Lua. Lua is a great scripting language, however there is a lack of documented patterns, and I'm sure everyone has their favorites, so newcomers and people wondering if they should use it or not can actually appreciate the ...

Good asp.net (C#) apps?

Any suggestions for good open source asp.net (C#) apps out there which meet as many of the following:? Designed well and multi tiered Clean & commented code Good use of several design patterns Web pages display properly in all common browsers Produces valid html and has good use of css Use of css themes. Prefer usage of css than tables...

Examples of Hierarchical-Model-View-Controller (HMVC)?

Hi, I'm interested in the Presentation-Abstraction-Control? (aka Hierarchical-Model-View-Controller (HMVC)) Architectural Pattern for constructing complex user interfaces (GUI or web) and was wondering if anyone was aware of any examples in the wild where I could read the code? I'm aware of the JavaWorld article and associated letters...

How does the Strategy Pattern work?

How does it work, what is it used for and when should one use it? ...

What are the best resources for design patterns and their uses?

When it comes to the use of design patterns, I am guessing there are three types of shops. Those who wouldn't know a pattern if it hit them in the face - these usually prefer the Ctrl-C / Ctrl-V approach to code-reuse. Those who spend hours a day searching their legacy code in hopes of implementing one more great pattern - these usually ...

What is the correct way to design/implement two (or more) classes that have "has a" relationships with the same object?

Suppose I have a design like this: Object GUI has two objects: object aManager and object bManager, which don't ever talk to each other. Both aManager and bManager have object cManager as an attribute (or rather a pointer to cManager). So when aManager modifies its cManager, it's affecting bManager's cManager as well. My question is w...

What's a good threadsafe singleton generic template pattern in C#

I have the following C# singleton pattern, is there any way of improving it? public class Singleton<T> where T : class, new() { private static object _syncobj = new object(); private static volatile T _instance = null; public static T Instance { get { if (...

What is the preferred practice for event arguments provided by custom events?

In regards to custom events in .NET, what is the preferred design pattern for passing event arguments? Should you have a separate EventArgs derived class for each event that can be raised, or it is acceptable to have a single class for the events if they are all raised by events from the same class? ...

Repository Pattern Implementation Experience

I am getting ready to start a new asp.net web project and I am going to LINQ-to-SQL. I have done a little bit of work getting my data layer setup using some info I found by Mike Hadlow that uses an Interface and generics to create a Repository for each table in the database. I thought this was an interesting approach at first. However...

Objective-C switch using objects?

I'm doing some Objective-C programming that involves parsing an NSXmlDocument and populating an objects properties from the result. First version looked like this: if([elementName compare:@"companyName"] == 0) [character setCorporationName:currentElementText]; else if([elementName compare:@"corporationID"] == 0) [character setCo...

Command Pattern : How to pass parameters to a command ?

My question is related to the command pattern, where we have the following abstraction (C# code) : public interface ICommand { Execute(); } Let's take a simple concrete command, which aims to delete an entity from our application. A Person instance, for example. I'll have a DeletePersonCommand, which implements ICommand. This com...