Creational design patterns are concerned with the way of creating objects. These design patterns are used when a decision must be made at the time of instantiation of a class (i.e. creating an object of a class).
But everyone knows an object is created by using new keyword in java. For example:
StudentRecord s1=new StudentRecord();
Hard-Coded code is not the good programming approach. Here, we are creating the instance by using the new keyword.
The above content is from a website
This says we should refrain from using new keyword
and use interfaces instead.so that our code is loosely bound.
Factory Pattern Or Abstract Factory Pattern Use interfaces for creating Objects. Singleton also comes in Creational Pattern, but we dont use interfaces in that for creating Object, instead we use getinstance
method. How come singleton is Creation Pattern. Please explain in brief, when would i use creational pattern.
Aucun commentaire:
Enregistrer un commentaire