mardi 8 janvier 2019

Enforce someone to use only factory for creating objects

I have a Shape interface and having Circle and Triangle classes which implements Shape interface. Lets say method is printShape() which just print type of shape.

Now there is one factory class ie ShapeFactory based on factory design pattern which provides Circle and Triangle objects.

Now i want to enforce everyone to use ShapeFactory for creating objects of Circle and Triangle.

May be if someone not aware about ShapeFactory exist then he/she can create object with new without using Shapefacoty. I want No one should create an object like Shape shape = new Circle.

How do I do that?

Aucun commentaire:

Enregistrer un commentaire