.
Scala, .
, , , . , :
FactoryBase
Factory[+F <: Factory[F,P], +P <: Product[F,P]] <: FactoryBase
SomeFactoryGroup[+F <: SomeFactoryGroup[F,P], +P <: SomeProductGroup[F,P]] <: Factory[SomeFactoryGroup, SomeProductGroup]
FooFactory <: SomeFactoryGroup[FooFactory, FooProduct]
ProductBase
Product[+F <: Factory[F,P], +P <: Product[F,P]] <: ProductBase
SomeFactoryGroup[+F <: SomeFactoryGroup[F,P], +P <: SomeProductGroup[F,P]] <: Product[SomeFactoryGroup, SomeProductGroup]
FooProduct <: SomeProductGroup[FooFactory, FooProduct]
, . , FactoryBase ProductBase. , , . FactoryBase, (SomeFactory | exist F <: Factory[F,P], exist P <: Product[F,P], SomeFactory <: F) ( Scala, ). , (, ). , FactoryBase Iterable[FactoryBase] .
. , factory (, , ). , factory , , factory .
- , : , ( ) . , :
productionrun.lookup(factory) = productionrun.mapFromFactoryToProduct.lookup(factory)
, FactoryBase ProductBase. . A (, ) B. , . , . , . , , , , . , ? , , .
: ( ) .
factory.lookup(productionrun) = factory.mapFromProductionRunToProduct.lookup(productionrun)
. , . ( , , , ). ( factory). , .
So to summarize. Have a class PRthat represents a production run. Create a method Factory[F,P].findProduct(pr:PR)->Product[F,P]implemented with Map[PR, Product[F,P]]. Ask the method makeProductto accept the value PRand add the result to the map using this value PR. You can wrap it in a method PR.lookUpProductByFactory[F,P](f:Factory[F,P])->Product[F,P]or some if you want. Also, wrap it in FactoryBase.findProduct(pr:PR)->ProductBaseand wrap it in PR.lookUpProductBaseByFactoryBase(f:FactoryBase)->ProductBase.
What is it. I hope these two solutions suit your needs.