Another important aspect to consider when writing your factory class is that, it does not make sense to create a new factory object for each invocation you can incorporate the singleton design pattern into your factory pattern code. The singleton design pattern will create only a single instance of your SimpleShapeFactory class. Since an abstract factory pattern is unlike factory pattern, where you need to have an instance for each of the two factories (i.e.SimpleShapeFactory and ComplexShapeFactory) returned, you can still incorporate the singleton pattern as an access point and have an instance of a HashMap, store your instances of both factories. Now your calling method uses a static method to get the same instance of your factory, hence conserving memory and promoting object
reuse:
ShapeFactory factory = ShapeFactory. GetFactoryInstance();
factory.getShape(1);
reuse:
ShapeFactory factory = ShapeFactory. GetFactoryInstance();
factory.getShape(1);