[Chicago-talk] [OT] Object question - subclass or make two
petemar1 at perlmonk.org
Sun Feb 1 12:31:44 CST 2004
I understand that interfaces aren'tnecessary to OOPerl, but has anyone ever
encountered a situation where it was necessary to enforce "design by
contract" in OOPerl?
From: chicago-talk-bounces at mail.pm.org
[mailto:chicago-talk-bounces at mail.pm.org]On Behalf Of Steven Lembark
Sent: Sunday, February 01, 2004 11:42 AM
To: Chicago.pm chatter
Subject: Re: [Chicago-talk] Object question - subclass or make two
-- Jay Strauss <me at heyjay.com>
> 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, placeOrder,
> 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
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