I tend to use composition everywhere I can, with a touch of inheritence to make life easier.
Example:
private final FortressCollection forts;
private final GruntCollection johnFarnham;
private final MaterialResources resources;
private final SubAtomicConverter converter;
NOTE: These classes are final being only a single instance is ever accepted, in the constructor.
Each of these classes have about 168 methods(operations) due to delegation of reference types.
The classes are in their own files and each file weighs in an estimated 16MB of space. The files only contain code.
Instead of writing so many delegates, you can just do this:
converter.getPowerSource().getPowerMineral().getNeutronics().getDuressType().getUltimateWeapon().destroyWorld(WorldAddress address);
*NOTE: “WorldAddress” is an enum.
Delegates should only be used in circumstances which reflect important top level functions, not for every bleeding method from every other reference type.
OOP states specifically that by using getters for reference types, you are breaking the rules.
When will OOP rules change to reflect the shortcut?
Sun have no problem breaking the rules though, I’ve seen non static getters from Sun’s classes to other reference types in Sun’s own libraries.
This is an outrage, why am I stuck obeying the rules when everyone else breaks the rules?
Example of a well written delegate:
public void destroyWorld(WorldAddress address){
converter.getPowerSource().getPowerMineral().getNeutronics().getDuressType().getUltimateWeapon().destroyWorld(WorldAddress address);
}
*The code in this post is an example and should not be taken literally.