- Create a
Producttype class. - Create an existential type
SomeProductfor theProducttype class. - Create a
Factorytype class with acreateProductmethod.
class Product p where
data SomeProduct where
SomeProduct :: Product p => p -> SomeProduct
class Factory f where
createProduct :: f -> SomeProduct- Create multiple
Producttype classes, e.g.ProductAandProductB. - Create an existential type for each type class, e.g.
SomeProductAandSomeProductB. - Create a
Factorytype class with one factory method for each product.
class ProductA p where
class ProductB p where
data SomeProductA where
SomeProductA :: ProductA p => p -> SomeProductA
data SomeProductB where
SomeProductB :: ProductB p => p -> SomeProductB
class Factory f where
createProductA :: f -> SomeProductA
createProductB :: f -> SomeProductB- Create a
Buildertype class with methods for build steps, which return new builders. - Create a
Directortype class with recipes created by composingBuildermethods.
class Builder b where
buildStart :: b
buildStepA :: b -> b
buildStepB :: b -> b
buildStepZ :: b -> b
class Director d where
makeFoo :: Builder b => d -> b -> b
makeBar :: Builder b => d -> b -> b- Create a
Prototypetype class with aclonemethod. - Create an existential type
SomePrototypefor thePrototypetype class. - Create a
Registrytype class with methods to get and set prototypes.
class Prototype p where
clone :: p -> IO p
data SomePrototype where
SomePrototype :: Prototype p => p -> SomePrototype
class Registry r where
setPrototype :: Prototype p => r -> String -> p -> IO ()
getPrototype :: r -> String -> IO (Maybe SomePrototype)Create a Singleton type class with a getInstance method.
class Singleton s where
getInstance :: IO s