❔ Inheritance or object references ? which one is more meaningful
My clinic should be like this:
or
4 Replies
if this is just a data model, neither is really more correct than the other
best I would say is "Is it that a ClinicService IS a PetService or does it own/manage a PetService"?
if this is a behavioral entity instead of just a data model, probably inheritance is what you want
but, really, the question still applies
it depends on your design, whether inheritance makes sense or not depends on how much the types have in common. But generally speaking there is the oop principle "favor composition over inheritance". So most of the times when in doubt, use composition as it gives you runtime flexibility while inheritance only takes static behaviour from parent at compile time
also think about semantics, inheritance is a
is
relationship
is a ClinicService
a PetService
?
I dont think it is, doesnt make sense to me semantically
if anything a PetService
is a ClinicService
but composition seems most reasonable, as in a ClinicService
(which could f.e. be a HospitalService) may have a PetService
as one of the services they offer
in UML class diagram terms, a ClinicService has 0..1 PetService is how I would do itas a rule of thumb, never use inheritance unless you're forced to
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.