design-patterns

What is the best way to replace or substitute if..else if..else trees in programs?

This question is motivated by something I've lately started to see a bit too often, the if..else if..else structure. While it's simple and has its uses, something about it keeps telling me again and again that it could be substituted with something that's more fine-grained, elegant and just generally easier to keep up-to-date. To be as ...

Difference between static class and singleton pattern?

What real (i.e. practical) difference exist between a static class and a singleton pattern? Both can be invoked without instantiation, both provide only with one "instance" and neither of them is threadsafe. Is there any other difference? ...

Objective-C Singleton instance as a static?

In Apple's documentation for their example of a Singleton, and I do understand there's more than one way to skin a cat -- but why do they bother ensuring the instance is registered as static? Take from: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html I'm referring to: ...

Why is the visitor responsible for enumerating children in the visitor pattern?

Based on the code I've found, it seems that the Visitor is required to known the structure of the visited objects and call on the needed children. This seems a bit clunky in some cases where the visitor would want to continue to work even if the visited classes are modified. I guess the real question is: Is their a pattern where the enu...

which design pattern to use for filtering query? c#

I have a database table with a list of products (clothing). The products belong to categories and are from different stores. Sample categories: tops, bottoms, shoes Sample stores: gap.com, macys.com, target.com My customers can request to filter products in the following ways: all products (no filter) by category by store by categor...

Help me pick a book on design patterns, refactoring, and/or testing

My role at my company is the sole developer, and my experience is limited (I got the job mostly because I'm probably the only person who will do it for the money they're willing to pay - but I digress) compared to the averge developer but more extensive than the average recent grad. As such I'm looking for some good books to fill in the...

Is massive Data Entry on the web feasable?

Is there any good way to design a web page for massive data entry? Datagrids seem to be the best way to handle this type of data entry and I think a client application like Access or SQLite+Frontend would be better suited for this than the web. Links to sites with a page for data entry would be greatly appreciated. ...

What is the relationship between "late binding" and "inversion of control"?

In his definition of OOP, Alan Kay points out he supports "the extreme late-binding of all things". Does his interest in late-binding share the same motivation as people's interest in IoC? In particular, would it be correct to say that both are motivated by the concept "specify as little as possible, and leave implementation details to ...

How do I tear down observer relationship in multithreaded C++?

I have a Subject which offers Subscribe(Observer*) and Unsubscribe(Observer*) to clients. Subject runs in its own thread (from which it calls Notify() on subscribed Observers) and a mutex protects its internal list of Observers. I would like client code - which I don't control - to be able to safely delete an Observer after it is unsub...

Classic Singleton implementation in OCaml

I am attempting to conceptualize the Singleton design pattern (qua Java) in OCaml and have seen ever instance allude to functors or modules, neither of which I am using in a proof of concept of GoF's work. Basically, I would like to recreate the following functionality using OCaml: public class Singleton { private static Singleton Uniq...

Pattern for Accessing Web Services

I need to access a Web-svc, run a bunch of queries and save the data to a store as part of an analysis. On top of this, there is a web-site that will query the datastore and show this data. We have features like this getiing added every month. How can I reduce the amount of boilerplate code that get's written. Add web svc ref Wrap met...

Advice on an ActiveRecord design pattern in C#

I'm in the process of writing a BSD licensed mini-ORM targeted at embedded databases (with support for ese, sqlite and sqlce out of the box) After working lots with Rails in the last year I have been thinking of implementing an Active Record pattern in C#. I have come up with some demo code and was wondering if the interface design i...

Factory object vs factory function

I have an ABC with several derived classes. To create these derived classes I use the factory pattern: .h file: class derivedFactory { public: base* createInstance(); }; .cpp file: base* derivedFactory::createInstance() { new derived(); } Is there any advantage to this over just having a free function: .h file: base* de...

What are the advantages and disadvantages of using the Front Controller pattern?

I currently design all of my websites with a file for each page, then include common elements like the header, footer and so on. However, I've noticed that many frameworks and CMSs use the Front Controller pattern. What are the advantages and disadvantages of using a Front Controller? Is the pattern simply used in frameworks and CMSs be...

Best practices with Unit testing on Third Party software API's (AutoCAD)

Hi, We are developing applications for use within AutoCAD. Basically we create a Class Library Project, and load the .dll in autoCAD with a command (NETLOAD). As so, we can use commands, "palettes", user controls, forms etc... AutoDesk provides an API through some dll's, running in their program directory. When referencing these dll'...

Best practice: initialize same component in multiple classes.

This is my first question so please be patient :) Background: I'm implementing an observer pattern and I have about 20 classes where I would eventually implement it. In order to use the subject and observer I need to: 1: initialize observer classes 2: create delegates 3: add delegates to the events This is probably very simple, but I d...

Itereting hierarchy of nodes - Visitor and Composite ?

Let's imagine I have a collection of nodes that I use for my Renderer class later on. Then I have a Visitor class that can visit node or whole collection. It's simple because my collection of nodes it's simply a wrapper to the std::list with few extra methods. The problem is I'd like to have a tree like structure for nodes(instead of si...

What in your opinion is the most abused design pattern?

Working with Java and Java frameworks I have started shuddering when I encounter Abstract Factory patterns. In my opinion this is the most abused design pattern. Not all frameworks abuse it but there are many. It doesn't fit all models and when almost 100% of the time you are going to be doing the same thing why abstract it? Which desi...

Design OOP question on Decorator and Strategy pattern C#

Say for example you have a base abstract class public abstract Foo { IFlyable _fly; ISwimmable _swim; void performSwim() { _swim.swim(); } void performFly() { _fly.fly(); } } And have behaviors/algorithm that you will have in your system interface IFlyable { void fly(); } interface ISwimmable { void swim(); } in...

Is mixin considered a design pattern?

Are mixins considered a design pattern? Structural? ...