Skip to main content

Posts

Showing posts from 2011

Factory Pattern

Factory pattern comes from creational design pattern category.main objective of this pattern is to instantiate an object and Factory pattern interface is responsible for creating objects but the sub-classes desides which class to instantiate. Im going to start with a simple example.Suppose an application asks for entering the name and sex of a person. If the sex is Male (M), it displays welcome message saying Hello Mr. <Name> and if the sex is Female (F), it displays message saying Hello Ms <Name>. First Im going to create a Person class.. public class Person {     public String name;     public String gender;     public String getName() {         return name;     }     public String getGender() {         return gender;     } } we have 2 sub classes which will print welcome messages public class Male extends Pers