jeudi 12 février 2015

abstract factory with handle body idiom

I have an abstract factory pattern hidden behind a handle-body idiom like the following:



FactoryHandle <>--------------- AbstractFactory
{+ createCommonThing() } /|\ {+ createCommonThing() }
|
| <<inherits>>
------------------------
| |
ConcreteFactory1 ConcreteFactory2
{ {
+ createCommonThing() + createCommonThing()
+ createFactory1Thing() + createFactory2Thing()
} }


Here FactoryHandle is injected with a ConcreteFactory (body) upon construction. It is able to expose only createCommonThing() method since it can be the only one present in the abstract base factory class without violating Liskov Substitutability principle.


My question is: How do I cleanly expose the Concrete Factory specific methods like createFactory1Thing and createFactory2Thing?


Should I have a separate handle class such as Factory1SpecificHandle which is composed of ConcreteFactory1 and exposes only the factory1 specific methods like createFactory1Thing()? And do the same thing for Factory2SpecificHandle? So, the client uses FactoryHandle if only common methods are to be used or Factory1SpecificHandle if specific methods are to be used. This somehow feels like a bad design.



Factory1SpecificHandle <>------------------ConcreteFactory1
{+ createFactory1Thing()} {
+ createCommonThing()
+ createFactory1Thing()
}


What would you suggest as a clean design here? If the question is unclear, please let me know and I can elaborate further. Thanks.


Aucun commentaire:

Enregistrer un commentaire