public interface EntityFactory
public Thing makeATable() { return new Thing("table"); }would become
public Thing makeATable(EntityFactory factory) { return factory.newThing("table"); }Finally, note that many of the current implementations of EntityFactory allow you to chain them together. For example, if you wanted to make sure that every Thing created is stored in both a module-specific memory and in the global default memory, you could use the following code:
BasicMemory moduleSpecificMemory = new BasicMemory(); EntityFactory storeInModuleFactory = new EntityFactoryWithMemory(moduleSpecificMemory); EntityFactory storeInBothFactory = new EntityFactoryWithStaticMemory(storeInModuleFactory); Thing myTable = makeATable(storeInBothFactory);If you use chained factories, remember that each Factory in the chain acts as a filter. This means the innermost factory in the chain gets the Thing exactly as its constructor creates it, optionally modifies it a bit, and passes it to the next outer factory. Thus if you want to store only fully configure Things in memory, the Memory stages of the Factory Chain should be the outermost stages.
EntityFactoryDefault, EntityFactoryWithMemory, and EntityFactoryWithStaticMemory for useful implementations of the EntityFactory interface.
,
for a useful starting point if you want to create your own ThingFactories.
Modifier and Type | Method and Description |
---|---|
Function |
newDerivative(boolean readOnly,
java.lang.String suffix,
Entity subject)
Constructs object with a name determined by suffix string provided; used
only in reading.
|
Function |
newDerivative(Entity t) |
Function |
newDerivative(java.lang.String string,
Entity t) |
Relation |
newRelation(boolean readOnly,
java.lang.String suffix,
Entity subject,
Entity object)
Constructs object with a name determined by suffix string provided; used
only in reading.
|
Relation |
newRelation(Entity subject,
Entity object)
Constructs a new relation, given a subject and an object.
|
Relation |
newRelation(java.lang.String type,
Entity subject,
Entity object)
Constructs a new relation, given a type, a subject and an object.
|
Sequence |
newSequence()
Constructs element-free sequence.
|
Sequence |
newSequence(boolean readOnly,
java.lang.String suffix)
Constructs object with a name determined by suffix string provided; used
only in reading.
|
Sequence |
newSequence(java.lang.String type)
Constructs element-free sequence.
|
Entity |
newThing()
Constructs object with a unique name.
|
Entity |
newThing(boolean readOnly,
java.lang.String suffix)
Constructs object with a name determined by suffix string provided; used
only in reading.
|
Entity |
newThing(java.lang.String type)
Creates a thing, with a type added to its primed thread.
|
Entity newThing()
Entity newThing(java.lang.String type)
Entity newThing(boolean readOnly, java.lang.String suffix)
Function newDerivative(boolean readOnly, java.lang.String suffix, Entity subject)
Relation newRelation(Entity subject, Entity object)
Relation newRelation(java.lang.String type, Entity subject, Entity object)
Relation newRelation(boolean readOnly, java.lang.String suffix, Entity subject, Entity object)
Sequence newSequence()
Sequence newSequence(java.lang.String type)
Sequence newSequence(boolean readOnly, java.lang.String suffix)