OO Design: use Properties or Overloaded methods?
- by Robert Frank
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();