Using composition with built-in interfaces
You can use composition with any interfaces,
including built-in interfaces. For example, you could give a custom object
all the methods of java.util.List
and delegate the implementation to an instance of java.util.ArrayList or another
List implementation.
For example:
class MyStringList implements List<String> {
delegate _internalList represents List<String> = new ArrayList<String>()
}
You could now use this class and call any method defined
on the List interface:
var x = new MyStringList()
x.add( "TestString" )
