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:
Procedure 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();
The approach with properties is pointless. You can’t use polymorphism properly since the functions take different parameters. You should just have distinct methods in the subclasses with the appropriate parameters.
Now, if you come back with a more complex version in which you only hold a reference to the base class then a different design would be called for, but it would be neither of the ones you have offered so far.