5 ms·
This presumes I ever want to ask an object what its type is, but that's generally not a good OO way to accomplish something. I'd rather tell the object what to
by gnaritas 16y ago
This presumes I ever want to ask an object what its type is, but that's generally not a good OO way to accomplish something. I'd rather tell the object what to do and assume it does the correct thing for its given type. If I must, I can always ask if it understands a given message, but that's to be avoided as well.
Interfaces are useful in defining what an implementor must provide, but an example implementation does this as well.
- rapind 16y agothis. Also, if it helps, just think of the impl as an interface with a default behaviour that should be overriden ;) If this is too forgiving, then we can even have the impl methods throw errors ("override me!") and simulate an interface.
- gnaritas 16y agoIn Smalltalk, I can have all the methods throw someMethod self subclassResponsibility and then use the realize class refactoring on a subclass to generate stubs for all methods I must implement, just like an interface.