Simple Factory design pattern in java
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.
0 comments:
Post a Comment