Presumably you will agree that some methods should tell you something - some kind of return value. It seems artificial and stupid that we "return the value we want to return if we really do not want to return anything, in which case we return this instead if it is not a static method, in which case we return void ."
What about:
- if itโs appropriate to return something, then return it
- If this is not so, then not
- (with some flaws for cases where the โfreeโ API really makes sense)
Also: think about inheritance; if I have a virtual method Foo() , then the return type must be Foo to declare the type:
public virtual SomeType Foo() {...}
Now imagine a subclass of SomeType , with Bar : SomeType and have an instance of Bar :
Bar obj = new Bar(); obj.Foo().SomeOtherMethodOnBar();
Polymorphism
does not account for poor APIs.
As a final thought: think of all the โbuttocksโ when you really don't want to hook methods ...
source share