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

141 Views Asked by At

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!

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

I bet he just meant "EmployeeFactory" in both those cases. It looks like just a typo.