design-patternserrata

Can't figure out this in Holub's pattern book


I started reading Holub's pattern book and not sure if this is a mistake (pg 59-61).

He has in listing 2-3

public interface Employee
{ void youAreFired();
}

public static class EmployeeFactory
{  private Factory() {}

 public static Employee create()
 {   return new Peon();
 }
 }

/* package*/ class Peon implements Employee
{   public void youAreFired()
    {  //lots of code
    }
 }

He is using Employee.Factory.create(). Factory is not a inner class of Employee, so how is using that?

Then two pages down he says Employee.Factory is a singleton. How? I think its a typo, Factory or Employee.Factory should actually be EmployeeFactory. I hope I am not missing something major in Java programming!


Solution

  • yeb there is single typo only:
    Proposed fix:
    the line public static class EmployeeFactory => public static class Factory

    revise what you wrote after considering above fix shall result in clearing the vision.