Given the following UML representation, how can i get an instance of a BullDog
, that only has getter methods exposed?
BullDog
should not have any of the setter methods available.BullDog
should only have getter methods (3 of them) availableBasically the question is .. what do i cast new BullDog
to?
Since HealthyPet and Pet are unrelated there's nothing you can cast to that will give you all 3 getter methods(getMetabolism(),getName() and getAge()). Now if HealthyPet extended Pet (and I'm really not sure why it doesn't) you'd be in business. Because then you could cast to HealthyPet, return that interface, and a caller would only see the 3 getter methods (of course I'm talking without fancy introspection which should allow them to discover everything).
You need HealthyPet to extend Pet. Then you cast your BullDog instance to HealthyPet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With