design-patterns

Design Patterns: How would you describe the MVC model?

Ok, I need to give some attributes to describe what MVC model means for a developer. And the only word that hits for the moment it's modularization (separation). And the funny thing is that I need to give some adjectives, not nouns. :| Any help? :) ...

How to initialize a class with many constructor arguments?

Hello! I have a class that takes many arguments to create. It’s a sort of an audio processor that needs a sample rate, sample resolution, number of channels etc. Most of the parameters have sane defaults. And most of them should be only settable in the initializer (constructor), because it makes no sense to change them afterwards. I do n...

Domain Driven Design: Aggregate root problem

Hi all, currently I dont know how to identify an aggregate root. I've got the following classes. - Garage - Organisation - RuleSet - Rule - OrganisationRule - GarageRule A Garage can have many Organisations. A RuleSet is an entity where Rules are referenced to. There are Rules that are directly associated with a RuleSet. Then the...

Why is there no "Iterable" interface in the STL?

The C++ STL does not seem to use purely abstract base classes (aka interfaces) very often. I know that most things can be achieved with the STL algorithms or clever template metaprogramming. But still, for some use cases (for example, in an API, if I do not want to be specific about the type of container I get, just about the elements ...

Is it better to have lot of interfaces or just one?

I have been working on this plugin system. I thought I passed design and started implementing. Now I wonder if I should revisit my design. my problem is the following: Currently in my design I have: An interface class FileNameLoader for loading the names of all the shared libraries my application needs to load. i.e. Load all files in ...

Attribute lists or inheritance jungle?

I've got 2 applications (lets call them AppA and AppB) communicating with each other. AppA is sending objects to AppB. There could be different objects and AppB does not support every object. An object could be a Model (think of a game, where models are vehicles, houses, persons etc). There could be different AppBs. Each supporting anoth...

Web service client design pattern (best practice)

Hi all, I have a web service deployed and ready to use. The client application is going to use this service synchronously and extremely frequent. The amount of data returned from the web service is also considerable. The web service client is a web application (liferay portlet). I have generated the client part with axis inside eclipse...

Can a Dictionary be sorted by a different key?

I have a requirement to retrieve an item from a data structure by key. But I also have a requirement to traverse that data structure in sorted order, using a field other than the key. Something like this (pseudocode, for illustrative purposes only): var list = new SortedDictionary<TKey, TSortField, TItem>(); How would I do this? Is...

How to make right architecture in Web application using Vaadin framework? Please Help!

HI, I am starting to developing web application and decide to use Vaadin + Java EE for reusable business logic. I know that Vaadin has MVP design pattern, but how to make good hierarchy of classes, write all in one MyApplication.java or make own Button classes or make Listeners in one side and UI components in other, and how to combine i...

iOS Design: Using the delegate pattern in a library

I have a library project that uses ASIHTTPRequest to make URL requests and parse the responses. The library will be used by a separate iPhone app project. If my iPhone controller code responds to a touch event, then calls into the library to make URL requests, how do I best perform the requests asynchronously? In the library, if I use ...

Code refactoring help

I have an example like this class A { A() {} public C createC () { ... } } class B { B() {} public C createC () { } } Objects for A and B are created based an an public enum D { ii, jj }; And I see code all over the place like D d; switch (d) { case ii: (new A()).createC(); break; case jj...

Proxy pattern vs. overriding

Suppose there is a interface Subject. interface Subject { void request(); } We have a RealSubject class. Suppose we want to enhance RealSubject, we can either use Proxy pattern that wraps around a RealSubject: class Proxy implements Subject { private RealSubject ref; void request(){ ... } } or we can extends RealSubject and...

How would you implement attribute lists?

When speaking about attribute lists I mean a generic list which stores additional information for a class. The simplest case: A class has a std::map<std::string, std::string>. The first string names the attribute (like "Color"), the second string describes the value (like "Yellow"). In this example another class which uses these attribu...

How to have procedural code wait for user input from a GUI before continuing?

In my program there is a complex calculation that requires the user to evaluate intermediate results. This works well in a command line application (which is what my code looks like now) because the interactive prompt halts the program execution until the user hits enter. The command line code looks something like this: def calculate(...

Interface-based programming in C++ in combination with iterators. How too keep this simple?

In my developments I am slowly moving from an object-oriented approach to interface-based-programming approach. More precisely: in the past I was already satisfied if I could group logic in a class now I tend to put more logic behind an interface and let a factory create the implementation A simple example clarifies this. In the pa...

Is this called "Circular Reference"?

Having the Observer pattern, we all know that based on its class diagram, the SUBJECT uses a reference to the OBSERVER. Meanwhile, the OBSERVER has a reference to SUBJECT in order to register or remove itself. Is this a "Circular Reference"? ...

The point of an Interface

Possible Duplicate: How will I know when to create an interface? I'm wondering about the point of using an Interface. Do you use Interfaces? If so, when do you decide to use them and when do you decide NOT to use them? I've currently got interfaces defined for my service layers and my repository layers, but I'm wondering i...

When is it beneficial to flyweight Strings in Java?

I understand the basic idea of java's String interning, but I'm trying to figure out which situations it happens in, and which I would need to do my own flyweighting. Somewhat related: Java Strings: “String s = new String(”silly“);” The best alternative for String flyweight implementation in Java never quite got answered Together t...

Proper way to connect UIActionSheet options to actions

While using a UIActionSheet in an iphone app, the typical methods of matching actions to buttons seem very fragile and aesthetically unpleasant. Perhaps its due to my minimal C/C++ background (more Perl, Java, Lisp and others). Matching on button indexes just seems like too many magic numbers and too disconnected to avoid simple logica...

How to implement the state design pattern in a JPA domain model

I want to implement the state design pattern in JPA. The way I am currently doing this is outlined in this blog post. The author uses an enum containing all available state implementations instead of creating abstract class/interface for state abstraction and writing implementation for each state. I find this approach very useful, since...