"Il y a peu de choses qui me soient impossibles..."
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:well...most people here would say that this design in general isn't good. When class 'B' extends class 'A', you should be able to say "B is an A". that doesn't work here: "a Son is a mother" or even "a Son is a Family". quite often, "a Daughter is a mother" doesn't even work.
So that my be a poor choice of naming. Instead of "Family", you could have a class name "FamilyMember", and then all the relationships work..."a Son is a FamilyMember", "a Daughter is a FamilyMember".
now..that is not your question.
In general, it IS a good idea to remove duplicate code to a parent class. I may change the sayKindOfOffspring() method to ONLY return the relationship type, and not the ", ". the method should do exactly what it says it does, and no more.
You can control the formatting in the Mother.speak() method. You may at some point want to print a sentence like:
"I gave my Son his allowance"
and for that, you don't want the comma. If the Son/Daughter class always returns a comma, you are stuck with it.
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Mike. J. Thompson wrote:What you have described there is the Template Method design pattern.
"Il y a peu de choses qui me soient impossibles..."
What's that smell? Hey, sniff this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|