In summary, a classic Factory design pattern looks like this:
You have an interface or abstract class, Worker.
You have some implementations of that, WorkerBill, WorkerJane, WorkerFred.
You have a Factory that has a method, often static, often called getSomething
or newSomething
.” It returns something of type Worker. That method chooses which of the implementors to use. It does a new WorkerBill (let's say) and returns it as the supertype.
The application code now has a concrete class, but typed as the abstract superclass or interface. It cannot use more methods than are in the interface. Voila.
52.15.47.218