Friday, March 05, 2010

Don't extend to extend functionality. Extend to only override functionality

Don’t extend to extend functionality

Extend to only override functionality

 

When an API is extended, the author of the API must factor in the fact that it would be extended. If not extension had exposed a means to invoke an API in a way that it was not designed to handle.

On the other hand when aggregation is used, only public APIs are used and hence the class is used as it was intended to be used. When authoring classes care must be exercised in deciding what must be private, protected, default, public and final (a way of saying this API does not support extension).

No comments: