design-patterns

Python borg pattern problem

I'm having problems implementing a borg in python. I found an example in an answer to this question but it's not working for me, unless I'm missing something. Here's the code: class Config: """ Borg singleton config object """ __we_are_one = {} __myvalue = "" def __init__(self): #implement the borg pattern...

Why would I ever use a Chain of Responsibility over a Decorator?

I'm just reading up on the Chain of Responsibility pattern and I'm having trouble imagining a scenario when I would prefer its use over that of decorator. What do you think? Does CoR have a niche use? ...

How should an object using the state pattern be transitioned to the next state?

I have an Order class which goes through a series of defined states. To aid with this, I have implemented the State pattern such that the Order object has a CurrentState member which implements an IOrderState interface. I then have concrete implementations of this interface such as OrderStateNew, OrderStateDelivered etc etc My question ...

Is this a design pattern?

All over our codebase we have this repeated pattern where there's an interface with one method. Is this a real design pattern? If so what is it and what would the benefits be? Here are a few examples: public interface IRunnable { void Run(); } public interface IAction { void Perform(); } ...

Pattern for unsaved changes

I'm developing a winforms app with lots of different forms and user controls. Is there a recommended pattern that I could implement that notifies the user that there are unsaved changes on the current form/control when the form/control is exiting and also when the app is closing? ...

Pattern to implement heartbeat between server and the client

I would like to implement a heartbeat functionality in the server that would periodically alert window clients of its liveness. There are few ideas I am considering but would appreciate suggestions and examples/references have a separate thread that would send a heartbeat to connected clients have different types of heartbeat to ind...

What are the practical uses of Factory Method Pattern?

I'm pretty new to Design Patterns.I just came across Factory Design Pattern. I understood that it delegates the instantiation to subclasses. But I didn't get the actual application of the pattern. In which scenarios can this pattern be used to good effect. I've heard of pattern abuse and would not like to indulge in that. Can anyone men...

implementing interfaces after the fact

I think, the following can't be done in Java. But I would be happy to learn how to implement something that resembles it. Suppose we have a class C, that is already used in compiled code. (We can neither change that code nor the original definition of C). Suppose further there is interesting code that could be re-used, if only C would ...

What's the best way to abstract the database from a PHP application?

My question is how does one abstract a database connection from the model layer of an application? The primary concern is to be able to easily change from different types of databases. Maybe you start with a flat file, comma-delimited database. Then you want to move to a SQL database. Then later you decide an LDAP implementation would be...

What are the design patterns which used in Struts 1.x framework?

What are the design patterns which used in Struts 1.x framework? ...

What are the design patterns which used in Spring framework?

What are the design patterns which used in Spring framework? ...

Empty method in an abstract class

I have just installed PMD to analyze my Java project. Really nice tool, highly recommended. Anyways, I got a few errors saying: "An empty method in an abstract class should be abstract instead" I checked out PMD documentation and the explanation says: as developer may rely on this empty implementation rather than code the app...

DDD - Dependecies between domain model, services and repositories

Just wanted to know how others have layered their architecture. Say i have my layers as follows: Domain Layer --Product --ProductService (Should the imp go into this layer?) --IProductService --IProductRepository Infrastructure Layer --ProductRepository (Imp of IProductRepository in my domain) Now when a new product is created i have...

Is Model-View-Controller the best design pattern for developing web apps?

Is Model-View-Controller (MVC) the best pattern for developing web applications? It seems most of the frameworks in use follow that pattern- Rails, Django, and now ASP.net MVC. ...

What is the difference between Builder Design pattern and Factory Design pattern?

What are the "Builder Design pattern" and "Factory Design pattern" the difference? Which is more advantageous? I want to test this patterns? How do I represent as a graph? ...

What's an alternative to MVC?

Seems like every project I'm on uses a Model View Controller architecture, and that's how I roll my own projects. Is there an alternative? How else would one create an application that has persistent storage and a user interface? ...

What is the difference between Dispatcher view and Service to work design pattern?

What is the main difference between Dispatcher view and Service to work design pattern? ...

Do design patterns increase or decrease the complexity of an Application?

I was just looking at this question about SQL, and followed a link about DAO to wikipedia. And it mentions as a disadvantage: "As with many design patterns, a design pattern increases the complexity of the application." -Wikipedia Which suddenly made me wonder where this idea came from (because it lacks a citation). Personally I a...

Traceable/documented calculations

We are about to redesign our calculation engine, and want each step in the calculation to be traceable/documented so that the user can get a complete report on what amounts make up each total. Are there any patterns or good examples on how to implement 'traceable' or 'self-documenting' calculations? ...

Is this the command pattern?

Hi, I have a MVP Gui and now I would like to define certain Actions or Commands (Modify, Save, Close, ...) for certain views. Is there an easy way to do this? Should I provide Commands for each View? ...