Simple factory refers to the newly created object through an interface

Any new type creation is handled with a change of code in the factory class and not in the client code

publicclassEmployeeManagerFactory

{

public IEmployeeManager GetEmployeeManager(int employeeTypeID)

{

IEmployeeManager returnValue = null;

if (employeeTypeID == 1)

{

returnValue = new PermanentEmployeeManager();

}

elseif
(employeeTypeID == 2)

{

returnValue = new ContractEmployeeManager();

}

return returnValue;

}

}

Factory Representation

From the above diagram, Factory representation block in the simple factory is replaced with Abstract Creator which further creates Concrete Creator A and Concrete Creator B Products providing another level of abstraction.

if (ModelState.IsValid)

{

BaseEmployeeFactory empFactory =

newEmployeeManagerFactory().CreateFactory(employee);

empFactory.ApplySalary();

db.Employees.Add(employee);

db.SaveChanges();

return RedirectToAction("Index");

}

ViewBag.EmployeeTypeID = newSelectList(db.Employee_Type, "Id",

"EmployeeType", employee.EmployeeTypeID);

return View(employee);

}

Step 8: Enhance the current Employee index view to add
Medical Allowance and House Allowance columns.

Step 9: Run the application and notice that we have
achieved the business requirement by using Factory Method pattern. Below
illustrated diagram depicts how we have converted the simple to factory method
implementation.