Michael Lazzaro wrote: > > What if a subclass adds extra, optional arguments to a > > method, is that ok? > > This is the scariest question, I think... In theory, yes, there are > lots of potential interfaces that would benefit from optional > extensions, & I've made a few. In strict terms, though, they violate > the whole idea of "common, invariant interface", so I never know if > what I've done is Acceptable, or a Shameful Hack... anyone care to > make a case either way on this one?
I don't think that the addition of an optional parameter violates any substitution principle: users of the base-class interface couldn't use the extra params (because they're not in the interface); but a user of the derived-class's interface can use the extra power (because they are in that interface). A derived class is always allowed to add things (thus, you can weaken preconditions, stengthen postconditions, add extra methods, return a more specific result, ...; but you can't strengthen a precondtion, nor weaken a postcondition, etc.) On a slightly different note, if we have interfaces then I'd really like to follow the Eiffel model: features such as renaming methods in the derived class may seem a bit strange; but they can be useful if you have have name-conflicts with multiple inheritance. Oh yes, and we need to make sure DBC stuff is part of the interface, not the implementation. Dave.