If the new method is implemented using the existing open interface, then perhaps this is more an object oriented to it as a separate function, rather than a method. At least Scott Myers claims that it is.
Why? Because it gives the best encapsulation. The IIRC argument states that the class interface must define the things that an object does. Helper functions are things that can be done with the / object, and not with what the object itself needs to do. Therefore, they do not belong to the class. If they are in a class, they can unnecessarily access private members and, therefore, extend the hide of this element and, therefore, the number of lines of code that need to be touched if the private member changes in any way.
Of course, if you want to access protected members, you must inherit. If your desired method requires a state for each instance, but not access to protected members, then you can inherit or combine to taste - the first is usually shorter, but has certain drawbacks if the relationship is not really "there".
source share