[Chicago-talk] 2 subclasses or Multiple inheritance

Steven Lembark lembark at wrkhors.com
Sun Mar 21 06:05:17 CST 2004

-- Jay Strauss <me at heyjay.com>

> I have a class which connects to Ameritrade (broker), and I have another
> class which connects to InteractiveBrokers.  Both of these classes have
> methods quote, connect, disconnect.  The class for InteractiveBrokers has
> a bunch of others too.  While the method names are the same their
> implementation is totally different, as are their required input parms.
> The classes don't share any of the same code, and I don't see them sharing
> any/much in the future.
> I'd like to be able to plug in other brokers as necessary.
> So my question is, do I make a base class like "broker" and make a
> Ameritrade and InteractiveBrokers that inherit from broker, or do a make a
> broker that inherits from Ameritrade and InteractiveBrokers?

You don't. If the dispatching object has a "tradermodule"
object stored it in you can use

    $dispatcher->{tradermodule}->foobar( args )

to handle any tradermodule you prefer. You can populate the dispatcher
entry with a classname initially then use:

    $dispatcher->{tradermodule} = $dispatcher->{tradermodule}->initialize;

to get an object.

Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 888 359 3508

More information about the Chicago-talk mailing list