Simple Factory design pattern in java

Factory pattern is a kind of Creational Pattern.
Download Source code
How the Factory work:
Given: Somewhere people write First name first and then last name but some where peole use backward way. If we fill a full name with comma, then the word is place before comma will be last name, and if we enter a full name without comma then the last word is last name.

In the below figure, there's a parent class Namer, and two child classes: FirstFirst and LastFirst. The NameFactory decides which sub classe to return depending on the input.


Post a Comment