Please enable JavaScript.
Coggle requires JavaScript to display documents.
Creational - Coggle Diagram
Creational
Abstract Factory
-
Sometimes we need some set of configurations like database, storage, initializers, etc to be switched depending on the context - QA, Development and production.
-
Simple Factory
You have Product hierarchy and the concrete product to be instantiated depend on some arguments, you can use a simple factory.
-
Factory Method
When new Product concrete implementations can be added, we can use a Factory Method in order to make the code open for extension but closed for modification.
ChartCreator
When implementing analytics, we use the factory method to allow add new Chart types (bar, stacked, pyramid, pie... etc)
We just need to Implement a new ChartCreator which gives the implementation to createChart abstract method.
-
Object Pool
Application server like Tomcat, allows to define data sources which will create a connection pool for database.
Cost of creating instances of a class is high, you need many of those instances for a short duration of time.
Builder
When I have an object which has a complex constructor or takes several steps to build, I put all that creation logic in a separate class.
Prototype
When create an object from scratch is costly or impossible, we use the clone method to create a copy from an existing object.