Overview
In the abstract, the MhAssortment
represent the details of a specific product line. This includes providing all MhSnapperSpawner
s, MhBehavior
s, domains of potential product values, as well as information about the product line such as name, description, and manufacturer. The MhAssortment
also provides the appropriate MhSpawnerSelector
for the product line which is used to select the correct MhSnapperSpawner
to generate a product for a given category in the product line that the assortment represents.
Populating an Assortment
When creating a new MhAssortment
many values must be populated for the assortment to be functional. This is usually done via overriding various methods on the MhAssortment
class. The following are the required methods to override when creating a new MhAssortment
.
Spawners
The initSpawners
method is used to populate the spawnerStore
with all the MhSnapperSpawner
s that are required for the product line. This method should be overridden to add all the MhSnapperSpawner
s required for the product line. To add to the spawnerStore
use the add
method on the spawnerStore
and pass in the MhSnapperSpawner
to add. The spawnerStore
is used by the MhSpawnerSelector
to select the correct MhSnapperSpawner
for a given category.
/** * Initialize snapper spawners. */ private void initSpawners() { //Add spawners for this product line spawnerStore.add(MhSnapperSpawner()); }
Behaviors
The initBehaviors
method is used to populate the behaviorStore
with all the MhBehavior
s that are required for the product line. This method should be overridden to add all the MhBehavior
s required for the product line.
To add to the behaviorStore
use the add
method on the behaviorStore
and pass in the MhBehavior
to add. The function mhStdBehaviorsInit
takes a behavior store and adds all behaviors standard to the abstract. This function should generally be called alongside adding any custom behaviors to the behaviorStore
.
/** * Initialize behaviors. */ private void initBehaviors() { //Add standard behaviors mhStdBehaviorsInit(behaviorStore); //Add custom behaviors behaviorStore.add(MhBehavior()); }
Domains
The domain
method is used to provide the domains of potential values for products contained within the product line the assortment represents. This method should be overridden to provide the domains for the product line. The domain
method takes a str
representing the property which should have it's domain returned. The domain
method should typically return a SubSet
.
/** * Retrieve a domain by key. */ public Object domain(str propKey, Object env=null) { switch (propKey) { case "aisleWidth" : return DoubleStepRange(0.1m, 1000m, 5cm); default: return super(..); } return super(..); }
Fixed Values
The fixedValue
method is used to provide the fixed values for products contained within the product line the assortment represents. This method should be overridden to provide the fixed values for the product line. The default
method takes a str
representing the property which should have it's fixed value returned. The default
method should typically return whatever type is required for the given property.
/** * Retrieve a fixed value by key. */ package Object fixedValue(str propKey) { switch (propKey) { case "frameWidth" : return 2cm; default: return super(..); } return super(..); }
Default Values
The default
method is used to provide the default values for products contained within the product line the assortment represents. This method should be overridden to provide the default values for the product line. The default
method takes a str
representing the property which should have it's default value returned. The default
method should typically return whatever type is required for the given property.
/** * Retrieve a default value by key. */ public Object default (str propKey, Object env=null) { switch (propKey) { case "aisleWidth" : return 1m; default: return super(..); } return super(..); }
Comments
0 comments
Please sign in to leave a comment.