OO Design: use Properties or Overloaded methods?

Posted by Robert Frank on Stack Overflow See other posts from Stack Overflow or by Robert Frank
Published on 2011-01-05T17:24:03Z Indexed on 2011/01/05 17:53 UTC
Read the original article Hit count: 181

Filed under:
|

Question about OO design.

Suppose I have a base object vehicle. And two descendants: truck and automobile.

Further, suppose the base object has a base method:

FixFlatTire(); abstract;

When the truck and automobile override the base object's, they require different information from the caller.

Am I better off overloading FixFlatTire like this in the two descendant objects:

Procedure Truck.FixFlatTire( OfficePhoneNumber: String;
                             NumberOfAxles: Integer): Override; Overload;

Procedure Automobile.FixFlatTire( WifesPhoneNumber: String;
                                  AAAMembershipID: String): Override; Overload;

Or introducing new properties in each of the descendants and then setting them before calling FixFlatTire, like this:

Truck.OfficePhoneNumber := '555-555-1212';
Truck.NumberOfAxles := 18;
Truck.FixFlatTire();

Automobile.WifesPhoneNumber := '555-555-2323';
Automobile.AAAMembershipID  := 'ABC';
Automobile.FixFlatTire();

© Stack Overflow or respective owner

Related posts about delphi

Related posts about oop