Factory of what? Of classes. In simple words, if we have a super class and n sub-classes, and based on data provided, we have to return the object of one of the sub-classes, we use a factory pattern. Let’s take an example to understand this pattern. Example: Let’s 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>. The skeleton of the code can be given here. public class Person { // name string public String name; // gender : M or F private String gender; public String getName() { return name; } public String getGender() { return gender; } }// End of class This is a simple class Person having methods for name and gender. Now, we will have two sub-classes, Male and Female which will print the ...
About Java and it's related concepts..