design-patterns

Passing around base class pointers

Scenario: I have the following defined classes. class Baseclass { }; class DerivedTypeA : public Baseclass { }; class DerivedTypeB : public Baseclass { }; // ... and so on ... class Container { list<Baseclass*> stuff; list<DerivedTypeA*> specific_stuff; // ... initializing constructors and so on ... public: void add(Basecla...

Class composed of other, larger, classes problem

Imagine you have a class with dozens of private member variables. Each member variable has a public getter and a setter function: class Foo { public: int GetA() const { return m_a; } : int GetZ() const { return m_z; } void SetA(int val) { m_a = val; } : void SetZ(int val) { m_z = val; } private: int m_a;...

java singleton pattern, should all variables be class variables?

If a class implements a singleton pattern, should all the variables be declared static? Is there any reason they shouldn't be declared static? Does it make a difference? ...

How to pass external variables to a private javascript outer closure function?

I may have made some poor design choices on this one. I have several objects being instanced like this. core.modules.trial = function(sandbox){ return{ alert_private : function(){ alert(omgpi); } }; }; I would like to do this: core.modules.trial[omgpi] = "external private var"; var trial = core.modules.trial...

interpreting string of commands

say you have to interpret a sting of command arguments like AABBCDEEFF... and the idea is that each character represents a command for which you have to take some actions on the class, the ugly solution is to write a big switch-case but i dont want to use that , can anybody suggest a more elegant solution ?? ...

Looking for concept for managing game level views, level selection views, preferences view, storing levels, environment variables.

I'm developing a puzzle game application - watch on youtube - for iPhone, and the actual "in-game" part is almost done. It is a separate Class (subclass of UIView) what initializes with a puzzle clue, puzzle pieces, and is ready to send a message for somebody if the puzzle has solved ("completeness" check invoked on every touchesEnded). ...

IRepository and relational data

I'm wondering what the recommended approach is for dealing with relational data with the IRepository pattern. My database has the following tables with column names in parenthesis: Plans (PlanId, Name, CreationDate, ModifiedDate, ViewId) Areas (AreaId, Name, nTop, nLeft, nRight, nBottom) Views (ViewId, nTop, nLeft, nRight, nBottom) P...

Adding validator symbol next to control on a Delphi form.

Hi, I have an application, where there are many forms which follow visual form inheritance. Every form has standard delphi components as well as custom components. Form validating functionality needs to be added. That is, A small red circle or astric image needs to be drawn next to a control, if the control's value is not valid. This...

Understanding UML of DoFactory Design Pattern - Decorator

I am trying to understand UML diagram describing Decorator Pattern at link below http://www.dofactory.com/Patterns/PatternDecorator.aspx I don't understand why there is a "Aggregation" relation between Decorator and Component. I believe it should be composition as Decorator cannot exist without the base component. ...

What is the requires/provides design pattern used by the T4 RequiresProvidesDirectiveProcessor class?

The MSDN Library documentation for the RequiresProvidesDirectiveProcessor class in the Microsoft.VisualStudio.TextTemplating namespace refers to a design pattern called "requires/provides". What is this design pattern? "The abstract base class for a directive processor that defines and implements a design pattern called requires/...

Patterns/Practices for designing Web Services

Are there any good patterns/practices used while designing Services. I came across this post today: http://stackoverflow.com/questions/1549743/when-to-use-the-decorator-pattern/1549771#1549771 Though I didn't completely understand but it really gives a new direction to think about designing services. Note: This question is not any tec...

create singleton class that has constructor which accepts arguments that are evaluated runtime

I want to have singleton class that its object is not statically created. having the following code, when I call ChromosomePool::createPool() I get the following error message : --> ChromosomePool.h:50: undefined reference to `myga::ChromosomePool::pool' <-- Can anyone please tell me how can I solve the problem ? class ChromosomePool ...

MVC design question

I'm developing basic GUI application. I have model class which counts time, I need to display this time to label in specific format. What is the right way to do it in according to MVC paradigm ? Logically I think it should be formatted in the view, but view is standard label control and implementing sub-label class seems a little bit ove...

Recurring configurations of a certain class: better to create subclasses or a factory?

Short summary: When you want to predefine certain instantiations of a class, is it better to create subclasses or a factory? Problem Context I have a view helper class MyWebserviceUrl that has a bunch of properties. It's purpose is to generate an url. I would like to be able to have preconfigured instances of this class, so that I do...

what patterns allow for object persistance using sql and nosql databases?

With the rise of the nosql movement we see different options for storing objects. Are there object persistence patterns that can handle both sql and nosql backends and allow to easily switch between the two? ...

C# Design Pattern - How to write code based on highly configurable user selections

Hi guys, I would like to write code without a lot of switch, if/else, and other typical statements that would execute logic based on user input. For example, lets say I have a Car class that I want to assemble and call Car.Run(). More importantly, lets say for the tires I have a chocie of 4 different Tire classes to choose from based o...

Design pattern for multiple services

What pattern(s) would be good to manage multiple API's? A scenario for using multiple API's would be a payment portal that allows clients to use different payment vendors to post transactions. So this system may need to utilize a papypal, fasttransact, x, y, or z API. ...

Missing a part / layer in my app

Hello all! I have an asp.net mvc application with three layers: - data layer with entities and repository (nhibernate) pattern - service layer with services (functions), which communicates with data layer. - ui layer with asp.net mvc application, which communicates with service layer. The problem is that the data in my entities is diff...

Use of Facade Pattern

How can I know that I need a facade Pattern at a point in my application development? How can I draw the line between Facade Pattern and Template Pattern? For example: In [this] article, we see that, int placeOrder(int CustomerID, List<BasketItem> Products) has a number of predefined steps in the algorithm. So why don't the author use ...

Singleton Pattern and Abstraction in JS

Although the example below exploits ExtJS, one can easily extrapolate to another framework. I am a fan of abstraction and data hiding (and OO in general); does anyone else hide data and members/functions or do you consider this attempt to be overkill? (Note: I believe strongly that DOM IDs should almost never be hardcoded. And, thou...