[Chicago-talk] Object question - subclass or make two
me at heyjay.com
Sun Feb 1 14:31:24 CST 2004
I get it
----- Original Message -----
From: "Steven Lembark" <lembark at wrkhors.com>
To: "Chicago.pm chatter" <chicago-talk at mail.pm.org>
Sent: Sunday, February 01, 2004 11:41 AM
Subject: Re: [Chicago-talk] Object question - subclass or make two
> -- Jay Strauss <me at heyjay.com>
> > Hi,
> > I have 2 classes that have identical methods. Should I write 2 classes,
> > or a parent and 2 subclasses? The class is "brokerage" as in Ameritrade
> > and InteractiveBrokers. They both have methods like: connect,
> > getQuote, getTransactionHistory... but the code to perform these actions
> > is totally different between classes.
> > I'm just wondering, what do I gain by making a single parent, and
> > subclassing?
> What you probably want is a generic (a.k.a. 'virtual') base
> class called "brokerage" that defines the generic methods.
> That puts most of your boilerplate in one place.
> The derived classes can then supply their own methods to
> modify behavior in the base class if necessary. Careful
> use of data in the derived classes will probably leave the
> base class doing all the work, or at least most of it.
> For example, supplying callbacks in the class data might
> allow a generic "place an order" method to deal with the
> variety between brokerage houses.
> Advantages are not having to hack the code in multiple
> places to fix/extend it and less work the next time you
> have to add a brokerage (i.e., reusability).
> Steven Lembark 2930 W. Palmer
> Workhorse Computing Chicago, IL 60647
> +1 888 359 3508
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
More information about the Chicago-talk