A question about composition and object orientation:
I am trying to implement more features for a class (Java TreeMap as an example).
public class TreeMap<K,V>
extends AbstractMap<K,V>
implements NavigableMap<K,V>, Cloneable, Serializable
Using composition is the way to go on this, so I would have to create first a reusable forwarding class, which will wrap the functionality of the class, while at the same time make it do only that so that It can be used elsewhere in the future.
public class ForwardingNavigableMap<K,V> implements NavigableMap<K,V>
{
...
}
I would then proceed with creating a wrapper class which inherits the newly created reusable forwarding class, like so:
public class BetterTreeMap<K,V> extends ForwardingNavigableMap<K,V>
{
/* some new cool features here */
}
What happens If TreeMap contains a number of fine features that I need in my class, that might not be as part of the NavigableMap interface? Should I then proceed in declaring my own interface for TreeMap, and implement that in my reusable class? Any input here is appreciated.