design-patterns

factory pattern apropriate for problem?

Well, I have a problem (ok, no real problem, but I wanna try out something new) with creating objects. Actually I have some orders, which contains a list of orderitems. These orderitems are used and so spreaded in the whole application, and I need a way to create them. The main problem is, I want to be able to create these objects in m...

How to model subclasses with different types of the same property in a language without generics?

I have 3 types of objects: Red, Green, and Blue. I have 3 kinds of devices that handle each type of object, respectively. No device can handle more than 1 type of object. Each "object handler" has a reference to an object which it is currently handling. In Java I'd do something like this: public class RedObject {} public class GreenObj...

Good book on Large scale Object Oriented System Design in C++

I am specifically looking for book which discuss about large scale system design (like Oracle server, Web servers) with extensive use of design patterns and meta programming (templates) in C++. thank you, ...

Run Once Code: Beyond Boolean?

I'm struggling for a pattern here. I have quite a few tasks that need to be run, but only need to be run once if they haven't been run before. Everything right now is handled by if/then, booleans and a hashtable. There are also nested children of the same effect (if/then, boolean) so their parent if/then, boolean isn't set to true until ...

How do I select a member variable with a type parameter?

Hi, I have a cache object that caches a number of different types of objects, as illustrated below: class Cache { public: ObjectTable<ObjTypeA> m_objACache; ObjectTable<ObjTypeB> m_objBCache; ObjectTable<ObjTypeC> m_objCCache; }; The (horrible) way I'm currently using the cache at the moment is directly accessing the cache...

What is the pattern used in log4j

Hi, I needed to understand the design pattern(s) used in log4j library. Since it provides loggers for various classes, it it a factory ? Any more inputs/pointers on these is greatly appreciated.. ...

Dynamically selecting the type of a component given the type of its generic type parameter

I frequently seems to come up to a situation where I have an abstract type which needs to be processed differently depending on which concrete implementation it has. As an example, an abstract class Payment could be subclassed as class CreditCard or class StoredCredit. To actually process the payment, we want to use an implementation...

Conventions for Assembling Multiple Error Message Exceptions

I have a list of validations to run against an object, each a separate method which takes the object as a parameter. As each validation fails, I will create an appropriate error message. At the end of the validation process, I will throw a custom exception containing a list of all the error messages. My question is, I've seen this don...

Java Interface-Implementation Pair

Is there a preferred method or style of creating a default implementation for interface methods? Suppose I had a commonly used interface where in 90% of the cases the functionality I wanted was identical. My first instinct is to create a concrete class with static methods. I would then delegate the functionality to the static methods w...

Gradual migration to a new database schema. ¿Suggestions?

(This question is about the best way to temporarily and programatically keep new records of two databases in sync, having very different schemas, and ignoring the old -outdated and no longer required- records.) I work on a company that provides TV programming information for guides, newspapers and websites. I have an old system that ha...

Factory Pattern Question

I am a N00b to OO. and people throw flames at me for not answering or not having any points. what can I say except,I am not qualified!!! Anyways here is my question I have seen more than enough examples of inheritance in your classic "Book" samples Animal, where Bear growls, Cat meows etc... Let's say I am creating Windows Controls dy...

Creating interdependent objects

Hi Stackoverflow, I have a design problem I cannot find a clean and nice solution to. I am developing in PHP but I believe this could occur in any language. My basic problem is that I have two objects that have circular interdependence at some level of indirection. That means I have a class (call it F) implementing the Facade pattern whi...

Do you know a design patterns book or video talking about Event Aggregation pattern?

I trying to write my own Event Aggregation class and i go some articles but i want to go step by step with this pattern, for example i want to create it with 2 simple classes, such as User class and Email notification class, so that when user change his password an email sent to him. I don't want to care for now with generics, i want it ...

How to avoid big switch statements?

I have an internal application in which one function is containing too many switch cases. This is developed in php.This specific function is used to write changes to database and also to keep a history of individual field values. So what it does is have a case for each field as different things needs to be applied for different fields...

Is it wrong to give permission other classes to change fields ?

Hello everybody I know that each class should to do its own job. So i always try process my fields by only in class's methods.If another class processing on my public fields i feel that there is something wrong but is it always right thing to make define private fields ? Would be bad design or code If i let other classes to change my pu...

How attach an event to a method in a common class?

Say i have the following two classes: public class User { public int ID { get; } public string Name { get; set; } public void ChangeName(string newName) { Name = newName; } } public class Mail { public void SendUserInfoChangeEmail() { t...

What design pattern is this? (Or, can you recommend a pattern for my specific problem?)

I have multiple Controller objects that either execute some script and then redirect to a specific page, or gather some data, send it to a View object and then display that View. Instead of having a page for each controller instantiation (for example main_menu.php, image_browser.php, manage_users.php), I have an index.php page that cont...

Trying to understand the event aggregator pattern

I am trying to implement the event aggregator pattern in a simple way to learn it step by step. But i didn't find any book or nice video tutorial talking about it's implementation. I just found some good articles such as this http://weblogs.asp.net/rashid/archive/2009/03/05/use-event-aggregator-to-make-your-application-more-extensible.as...

Refactoring Form.ShowDialog() code to MVP

Hi All, I have a WinForm and few properties that are set on it. for example : Name,Address are accepted on the Form. (many more properties in actual example) The current implementation is somewhat similar to frmName frmView = new frmName (); //frmName is WINFORM frmView.Name= "ABC"; //any valid string or read this from file frmV...

How ISubject and Subject will look like in this sample and are the sample using them in the right place?

I got this sample http://jfromaniello.blogspot.com/2010/04/event-aggregator-with-reactive.html, Which describe event aggregator pattern using .net 4.0 but i didn't find in the sample code the ISubject interface and the Subject class and i found the he is using them in the EventAggregator class, is it right to use them like that and wh...