Hamburgerclass that is easy to test, but it's currently awkward to work with. Instantiating a
Hamburger, and now all the different pieces of code that make
Hamburgers have to understand how
Hamburgers need to be created this factory will become confusing. The factory is also responsible for knowing how to create four different components. This is a lot for one function.
Injectorobject. An Injector is a lot like the factory function above, but more general, and powerful. Instead of one giant factory function, an Injector has a factory, or recipe (pun intended) for a collection of objects. With an
Injector, creating a
Hamburgercould be as easy as: