public interface Featurable extends FeatureProvider
Feature
.
Such a system allows to reduce direct complexity by splitting object implementation into different classes. Each will
provide a specific sub system, called a Feature
. They will compose a complex system, called a
Featurable
.
Problematic
Implementation of an object, which may move and can collide other objects which may not all move.
Naive solution
One big object, implementing moving and colliding.
Feature solution
Sub system implementation, sub system composition:
This way, our object is now very simple, as it only declares its required features. Implementations are localized in specific classes, which helps to avoid god class if our object want to also jump and throw something.
Caution
The counterpart of such a system is the low typing of our final object, as it is only known at runtime, even if they
are statically declared. An object is just a set of something, which can lead to undesired exceptions if not
used correctly. Documentation must explicit the required Feature
, in order to use an object properly.
An alternative could be direct Feature
implementation, combined with simple delegate.
Modifier and Type | Method and Description |
---|---|
void |
addFeature(Feature feature)
Add a feature.
|
<T extends Feature> |
addFeatureAndGet(T feature)
Add a feature and retrieve it.
|
void |
checkListener(Object listener)
Check object interface listening and add them automatically.
|
Media |
getMedia()
Get the associated media.
|
getFeature, getFeatures, getFeaturesType, hasFeature
void addFeature(Feature feature)
feature
- The feature to add.<T extends Feature> T addFeatureAndGet(T feature)
FeaturableConfig.NODE_FEATURE
nodes.T
- The feature type.feature
- The feature to add.void checkListener(Object listener)
Feature
provide listeners, this will
allow to add them automatically.listener
- The listener to check.Media getMedia()
null
if none.Copyright © 2017 Byron 3D Games Studio. All rights reserved.