When writing a program in Java, if I have a special case of an object that needs to be handled differently by the main class, but it does not require any additional methods, is it better to add a Boolean parameter to the constructor of an object such as isSpecial, and check Is the object special in the main class or for creating a new object that extends the original?
Example:
I have a Cat class. If a cat has whiskers, I want to print "This cat has whiskers!" in the main class.
Would it be better to have a WhiskerCat class or just add a boolean parameter to a Cat constructor such as hasWhiskers?
source
share