-
Notifications
You must be signed in to change notification settings - Fork 0
Factories
Factories are used to hide the instantiation (creation) of objects from the client that wants to work with it. They are most useful in situations where you have multiple types of something that are basically treated the same way. In our application the screens are a good example: There are multiple of them, but the application treats them all the same way (appendToApplication / destroy). Those two methods are basically the '''interface''' of all screens, the one thing they have in common. The application is the client that wants to work with the interface and doesn't care what each individual screen does specifically.
The concept of closed factories is that we don't want to change the factory every time we need to add e.g: another screen. Closed factories provide methods to register types with ids and retrieve instances by asking the factory for an id. The factory does not know anything about its registered types -> the classes that want to be registered do it themselves.