Create Java objects based on their type

I have a set of data objects, which correspond to rows in RDMS table, as in ClassA -> Rows of TableA ClassB -> Rows of TableB . . . ClassZ -> Rows of TableZ I am fetching these records using JDBC and creating objects from the result set(Please no

Robust C ++ Event Model

I've put together a simple C++ event pattern, that allows the following: struct Emitter { Event<float> ev; void triggerEvent() {; } }; struct Listener { void gotEvent(float x) { ... } }; int main() { // event source and listener unawar

Please give an example of a factory method template

I read the difference between factory pattern and factory method pattern. Factory method pattern defers instantiation of an object to subclasses. Also it is a Factory Method because the children of "Creator" are responsible for implementing the

Name of the design reason: get class level class

Especially in unittests we use this "design pattern" I call "get class from class level" class FrameWorkHttpClient(object): .... class FrameWorkTestCase(unittest.TestCase): # Subclass can control the class which gets u

Private methods or internal class

I am working on a class which needs couple of helper methods. This methods are going to be used only by this class. So I am wondering which will be best practice i.e. whether declaring these helper methods as private methods or group them and put ins

Is ActionListener in the controller for Java GUI App good idea?

I't trying to follow MVC pattern. In internet as I see the most famous example is calculator, for example here. I began to use this implementation of MVC pattern. But now I have some doubts about action listeners in controller as they tend to move to

Playframework Servicestack resting with MV *

We Love Play!! Have used for small projects and pleased with the performance and productivity. Need few suggestions or comments for the architecture for our new venture which is going to be on play-framework. Our new venture is to use REST Service st

Singleton Access Private Methods public access methods

I have created a single class but I'm having a little trouble accesing the public methods from the private ones. My example is this: var mySingleton = (function () { function init() { function privateMethod(){ publicMethod(); //this.publicMethod() al

What are the responsibilities of the data layer?

I'm working on a project where I had to add a data layer to my application. I've always thought that the data layer is purely responsible for CRUD functions ie. shouldn't really contain any logic but should simply retrieve data for the business layer

How (which design model) to manage the addition of new fields?

I have been doing web app for medical data collection for a long time. Clients always have this kind of request : adding a new field in the form, for example they want add "gender" in demographic form. Every time they request, I have to 1. Add a

Trouble with Decorator Pattern, iOS / UICollectionViewCells

I am trying to 'decorate' UICollectionViewCells using the Decorator pattern. For example, if I have a BaseCell : UICollectionViewCell I would like to be able to do something like this: BaseCell *cell = [[BaseCell alloc] initWithFrame] cell = [[Glowin

Design templates in exception handling

I am actually writing a library class which could be used by multiple classes. I am simplying the example so as to make a point. Lets say I have three classes: A, B and C: public class B { public static string B_Method() { string bstr = String.Empty;

DDD: Caching Aggregated Objects Received from the Server

Suppose I have a repository (ContactsRepository) with method like getAllContacts(userId). The (ContactsRepository) fetch all data from server. After first call getAllContacts(userId) method I want to cache this data. My question is where I should rea

Why the plant is insufficient for sorting

Strategy is a pattern aimed at allowing you to add new (in your case sort) algorithms to your software without breaking the clients of the algorithms. It's an investment in design complexity that will pay off if you need to add new algorithms without

Bridge or factory model?

In my design, at the first time, I was designing a factory pattern. But one person recommend use better the bridge pattern. This is my scenario: How to improve my abstract factory pattern? I just want to know which pattern is the best for this scenar

Replacement for huge case reports

I'm trying to improve a Java project which uses a lot of large case statements. In cases where the case statement is used, it is used to handle an event which has an attribute associated to it. For example: public void jumpOverWall(int wallID) { swit

javascript subobjects and definition templates

I have been mauling over this for while now, and wonder if anyone could point me in the right direction. I have the following object definition: var foo=function(){}; foo.prototype={ foo1:function(){}, baz:{ baz1:function(){} }, bar:function(){ funct

What is the best way to structure this kind of code?

I have a function that need to analyze packet after packet and decide what to do. For each packet the code must: Read a packet, on timeout return an error code. Check for corruption, if positive log it and and go to 1. Check for an abort packet, if p

C ++ proxy class

Is there any way to easily implement a proxy class pattern in C++? Not using AspectC++ or other heavy tools, just built-in macro or templates. Explaining what I want: class base_class { public: virtual void method_one() { ... } virtual void method_tw

Refactoring my code: Conditions based on different variables

Given: internal void Configure(ButtonEventArgs args, IBroker broker, FunctionEntry entry) { int phase = broker.TradingPhase; if (args.Button == ItemType.SendAutoButton) { if (phase == 1) { entry.SetParameter("ANDealerPrice", -1); entry.SetParame

Understand the order pattern in Swing

I can see how Swing uses Decorator and Observer pattern. Observer: Every component(eg. JButton) is a subject which can add observers(ActionListeners). When someone pushes a button it notifies all its ActionListeners by calling their actionPerformed(A

What are the common competition pitfalls?

I'm looking into educating our team on concurrency. What are the most common pitfalls developers fall into surrounding concurrency. For instance, in .Net the keyword static opens the door to a lot of concurrency issues. Are there other design pattern