views:

101

answers:

2

I have a class that has everything already implemented but its initialization process is different for every child class.
Is there a better idiom to replace the ctor? Is there something more generic/dynamic that I should use?

+5  A: 

Does each subclass really represent a different concept than the superclass? If the only thing that changes is the initialization, and none of the data or later behavior, could you just add parameters to the constructor to control that initialization?

Asher Dunn
It just presents an abstract->concreate hierarchy. All the constructor does is connecting different events to object funcions. It's always the same operation but on different objects and even on different number of them.Also each object might bind himself to a different set of events
the_drow
+9  A: 

Or use static factory methods. This allows you to have different names for the "constructor" that shows the intent.

James Keesey
Good point. Better than my suggestion =)
Asher Dunn
I'll bet James Keesey hits the rep ceiling today.
Joshua