design-patterns

Timesheets: Retrieve data using SQL, LINQ or class?

My problem is that I want a grid that is populated with a set of times spent on tasks. It needs to have the days of the week at the top (these would preferably be fixed - i.e. Sun, Mon... Sat) and task names down the left column. The contents of the grid will have the individual hours spent for that day on that task. What would the be...

Deriving static members

I have a base class that has a private static member: class Base { private static Base m_instance = new Base(); public static Base Instance { get { return m_instance; } } } And I want to derive multiple classes from this: class DerivedA : Base {} class DerivedB : Base {} class DerivedC : Base {} However, at ...

Best way to handle input and state changes for multiple states?

I have an application that has multiple states, with each state responding to input differently. The initial implementation was done with a big switch statement, which I refactored using the state pattern (at least, I think it's the state pattern. I'm kind of new to using design patterns, so I tend to get them confused) - class App { ...

How do the Proxy, Decorator, Adaptor, and Bridge Patterns differ?

I was looking at the Proxy Pattern, and to me it seems an awful lot like the Decorator, Adaptor, and Bridge Patterns. Am I misunderstanding something? What's the difference? Why would I use the proxy pattern veses the others? How have you used them in the past in real world projects? ...

Static classes in c#

In answering this question (http://stackoverflow.com/questions/352317/c-coding-question#352327), it got me wondering... Is there any danger in regarding a static class as being equivalent to a non-static class instatiation that implements the singleton pattern? ...

Declaring Presenters and Views

I'm making a WPF application that is comprised of Screens (Presenter + View). I want to be able to declare these screens in a config file or SQL database. I have been trying to come up with a good solution I've given up and am asking how some of you design this sort of thing? I've been working at this for over a week and every solution I...

undo redo with an auto delete mechanism

My application is developped in C++ using Qt and is using signals and slots. Let's say I have the following classes (pseudo-C++ code) : class Ball { Color m_Color; int m_Size; }; class Player { public: setBall(Ball* pBall) { if (pBall != m_pBall) { Ball* pPreviousBall = m_pBall; ...

Extending both sides of a Visitor/Bridge pattern

Say I have a hierarchy of classes, let's use the classic Shape examples: abstract class Shape Circle : Shape Square : Shape I have a second hierarchy of renderer classes that handle the rendering of shapes in different ways: abstract class ShapeRenderer HtmlShapeRenderer : ShapeRenderer WindowsFormsShapeRenderer : ShapeRenderer Al...

Design patterns for Apple's Cocoa frameworks: MVC, MVP, Passive View... where is Apple heading???

To lay the groundwork for this question, I'm going to state that I'm getting my definitions for MVC, MVP, and Passive View from the following: Model View Controller (MVC) Model View Presenter (MVP) Passive View (PV) Apple has always stated that it uses the MVC design pattern, but I noticed in OS X 10.5 we've gotten NSViewController, KV...

What is the best approach to binding commands in a ViewModel to elements in the View?

Anyone who has tried to implement RoutedCommands in WPF using M-V-VM has undoubtedly run into issues. Commands (non-UI commands that is) should be implemented in the ViewModel. For instance if I needed to save a CustomerViewModel then I would implement that as a command directly on my CustomerViewModel. However if I wanted to pop up a wi...

What do you call an object level equivalent of Mixin/Traits system, is there a Pattern name for it?

I previously asked about what Mixins were, and have begun to get the gist of what the pattern means. But it got me wondering if there is a common pattern name for doing something like Mixins at an Object level as opposed to the Class level. Pseudo code (in some non existent language): Class MyClass { function foo() { ...

OOP design question - keeping track of many similar things

I'm designing a Data Access layer for an C#/ASP.net application and I have a question regarding the treatment of parameters in sql queries. At the moment, when a query needs a dynamically set parameter for the Where clause I have to (1) define a variable to hold the value, (2) add a new QueryStringParameter to the SqlDataSource's Select...

unidentified syntax in domain object constructor

Can someone help me identify what the purpose of this unidentified syntax is. It is an extra little something in the constructor for this object. What I'm trying to figure out is what is the "< IdT >" at the end of the class declaration line? I think that this is something I would find useful, I just need to understand what it is why so ...

Design Pattern for Components that depend on each other

We are building a "configurator" application for conveyors. Basically user comes in and picks a model, then start picking the parts they want. Some components have dependencies on other components. E.g. if I pick Part A, then I am required to select 1 or more Part B's. It is somewhat similar to configuring a PC at Dell.com. The app will ...

Design pattern for methods in another class

I am looking for a specific desgin pattern. For example i have an article class, clsArticle. This class contains member variables like Id, title, author, article, and so on. Imagine i want to show all the articles in a list. So somewhere i have to create a method getAllArticles(). Since clsArticle is not responsible for getting all the ...

Which implementation of Iterator should I use in PHP, and why?

I'm trying to refactor a large, old project and one thing I've noticed is a range of different Iterator implementations: while($iterator->moveNext()) { $item = $iterator->current(); // do something with $item; } for($iterator = getIterator(), $iterator->HasNext()) { $item = $iterator->Next(); // do something with $it...

Any patterns for modelling board games?

For fun, I'm trying to write one of my son's favorite board games as a piece of software. Eventually I expect to build a WPF UI on top of it, but right now I'm building the machine that models the games and its rules. As I do this, I keep seeing problems that I think are common to many board games, and perhaps others have already solve...

Why use the Visitor Pattern?

Duplicate of: When Should I Use The Visitor Design Pattern Why would someone want to use the visitor pattern? I've read a couple of articles, but I'm not getting something. If I need a function to bill a custom, I could use Custom.Accept(BillVisitor) or something like Bill(Customer) The second is less complex, and the Bill functi...

What's the best to way to manage a singleton?

I am messing around with different PHP logging frameworks. I am currently trying PEAR::Log. I figured that I would use its singleton function to make sure there was only one instance of the class around. I have a small daemon-like script I wanted to add logging to because it was probably the simplest script in the system to test. Thi...

Looking for a better C++ class factory

I have an application that has several objects (about 50 so far, but growing). There is only one instance of each of these objects in the app and these instances get shared among components. What I've done is derive all of the objects from a base BrokeredObject class: class BrokeredObject { virtual int GetInterfaceId() = 0; }; And...