design-patterns

Dynamic responding to events

I have three components. A windows forms control (custom made), a main class and a plugin class. The plugin generates an update event, where something should be added to the control. This could be a string, a string with an url, or another control, but maybe in the future, something else. What is the best way to design something like t...

Linking two Abstract Factory Patterns in Java.

I am writing a quote-matching program in which two Abstract Factory Patterns are required, these are two interfaces; QuoteFactory and ModeFactory. ModeFactory switches between EasyMode and HardMode and QuoteFactory picks out Quotes between several different subjects (i.e. PoliticalQuotes, SportsQuotes). In short, the user will pick a mod...

What's the best way to implement observer pattern for many types?

I have an agent that monitors for certain conditions. For each condition, I would like to notify a different observer, because the responsibility for that condition lies with the observer. The way to do it for a single observer/subject in C++, according to wikipedia, is to create a virtual class (similar to a Java interface), which def...

How to manipulate data in a TreeView? Should i use the ViewModelPattern?

A part of the editor i'm writing uses a Wpf-TreeView. I'm using DataBinding and an ItemTemplate to populate the TreeView. So far i'm manipulating the ItemsSource(mostly ObeservableCollection's) dircetly(using for example Drag&Drop). But now i read this and i'm not sure if it would realy simplify thinks for me. And before i go on with the...

Design Pattern: Builder

I have looked for a good example of a Builder pattern (in C#), but cannot find one either because I don't understand the Builder pattern or I am trying to do something that was never intended. For example, if I have an abstract automobile and abstract builder methods to create car parts, I should be able to send all 30 of my choices to ...

Design patterns, are there any recommended patterns for juniors to try to apply, and why?

I noticed the last few weeks that programmers with higher experience do not discuss "coding" issues very often, rather they discuss design issues. I really love to learn about these patterns, I know the concepts of OO Programming and Design, I'm already applying a decent amount of these principles in my daily work, I try to keep my compo...

C++ Factory method pattern implementation question

I've been looking at the example C++ Factory method pattern in Wikipedia http://en.wikipedia.org/wiki/Factory_method_pattern and have a couple of questions: 1) Since the factory method is static, does that mean the newly created object won't go out of scope and have the destructor method called when the factory method exits? 2) Why re...

Factory class knows too much

UPDATED I've updated the example to better illustrate my problem. I realised it was missing one specific point - namely the fact that the CreateLabel() method always takes a label type so the factory can decide what type of label to create. Thing is, it might need to obtain more or less information depending on what type of label it wa...

Need an elegant way to invoke arbitrary code on a specified interval

Ok, I have a game server running in Java/Hibernate/Spring/Quartz. The game clock ticks with a Quartz timer, and that works just fine. However, I have many other things that need to happen at specific, tweakable intervals (in game time, not real time). For instance, every 24 hours game time (~ 47 minutes real time, depending on the ser...

model view controller listview interface query

Just starting out using model view controller design pattern in a mobile application and I have a quick query. Basically if I have a listview control on my view and my controller needs to access properties on the listview when an action is performed, like the items checked and the listviewitem vales, do I just expose on my view interfac...

Is there a standard 3rd party Python caching class?

I'm working on a client class which needs to load data from a networked database. It's been suggested that adding a standard caching service to the client could improve it's performance. I'd dearly like not to have to build my own caching class - it's well known that these provide common points of failure. It would be far better to use...

What is the Serialization Proxy Pattern?

Alas, Google has failed me... What is the Serialization Proxy Pattern and where can I learn more about implementing and using it? ...

java interface design: how to handle stateful processing

I'm having trouble designing a good architecture for a particular portion of my application, especially where maintaining state is involved. I have a group of parsing operations: My class Reader reads in a block of data into a buffer and handles the overall control flow. My class Parser takes the block of data in the buffer and a Parse...

when should I use the session-per-request pattern

I see this pattern everywhere, but Linq to SQL does not implement it. If Session/Unit-of-Work objects are lightweight (can be created and destroyed without performance penalty), and connection pooling keeps database connections alive, why and when do I need the session-per-request pattern? ...

How to record transactions for money flowing into an acounting system?

I've been reading about accounting patterns described by Martin Fowler in his book "Analysis Patterns - Reusable Object Models". I understood the basic concepts: account, entry, transaction, etc; but I am not quite clear when it comes to the money flow when external funds flow into the system. To make sure that no money is created or des...

How does a factory know which type of object to create?

I believe the factory method design pattern is appropriate for what I'm trying to do, but I'm not sure how much responsibility (knowledge of subclasses it creates) to give it. The example of using the factory method pattern at Wikipedia describes the situation I'm in almost exactly: public class ImageReaderFactory { public static ...

MVP on semi-complicated pages

Hi, I'm working on .NET 3.5 form application with slightly complicated behaviour. It's for a book inventory. To give you an idea, a workflow would be: The user enters an ISBN code If the ISBN is valid, check whether it exists, If it's valid and it exists, show book details and enable save button, if not, show 'add book'-button, If it'...

What do you think of my IDisposable pattern implementation?

What do you think of the following IDisposable pattern implementation? public class Connection : IDisposable { private Socket _socket; public bool IsConnected() { if (_socket.Poll(1, SelectMode.SelectRead) && _socket.Available == 0) return false; return true; } public void Disconnect() ...

Proper way to display pop-ups using WPF M-V-VM pattern

I had a question about the VM responsibilities when it comes to pop-ups. When an app is popping a message box or some kind of dialog (with MVVM), the two options that we have are: putting UI (ShowDialog()) code in VM which seems bad have VM send some kind of event that UI can subscribe to and display a dialog in the code behind (but...

How do you navigate between views in MVP using C# WinForms?

As I understand, when we use MVP we move all presentation logic to the Presenter. But we don't want to let the Presenter know about view implementation, so how can we navigate to another screen in the application? How do you manage application flow on your real application? ...