Creational Design Pattern: Factory Design Pattern
Creational Design Pattern : Designing pattern related to creation of a object or instance of Class. 1) Factory Design Pattern: When we have a super class which have many sub class and we have to return instance of a sub class according to input. Following are the main part of factory design pattern: # super class: super class may be interface , abstract class or a normal java class. # sub classes: # factory class: # super class: public abstract class Computer { public abstract String getRAM(); public abstract String getHDD(); public abstract String getCPU(); @Override public String toString(){ return "RAM= "+this.getRAM()+", HDD="+this.getHDD()+", CPU="+this.getCPU(); } } # sub classes: Let’s say we have two sub-classes PC and Server with below implementation. public class PC extends Computer { private String ram; private String hdd; private String cpu; public PC(String ram, String hdd, String cpu){ this.ram=ram; this.hdd=h...

Comments
Post a Comment