First, run the project, make a get to the correct endpoint and view the output.
The actors are (per reference #1):
- Client – This object is the ‘glue’ that ties it all together. The client has a reference to each type of the related objects and the output is added to it from the factory that is injected into the constructor at run time. My implementation of the client is a combination ‘Client.js’ and ‘initializeClient()’ in ‘abstractFactoryDriver.js’. Instead of using the constructor from the example in reference #1, I chose to add a ‘setFactory(arg)’ method to inject the factory. One complication was that I got a run time error that I wasn’t expecting. In reference #1’s example, each object has the output from the supplied factory. Because the factory was not set until run time, I opted to leave the object references as undefined and set them at run time as well.
- Abstract/Concrete Factory – Similar to the factory pattern, this factory has a method that returns a specific object. The only difference is that there is more than one. My implementation is a combination of ‘AbsFactory.js’ and the ‘initializeFactory()’ method in ‘abstractFactoryDriver.js’. In ‘initializedFactory()’, I use the Object.create(arg) to create the concrete factory. Something to note is that I took a slightly different approach than reference #1’s example where I only created one factory instead of three for each object. But with all things, there is always more than one way to do the same thing 😉
- Abstract/Concrete Objects – Similar to the factory pattern, the object being created is based on an abstract object. The only difference is that there is more than one. Another difference I took was to use one abstract object to make my concrete objects. I suppose how you do this this depends on the objects being created. Since mine only differed by a couple of properties, I chose simplicity 😉 My implementation is a combination of ‘AbsObjectX.js’ and the ‘initializeFactory()’ method in ‘abstractFactoryDriver.js’. In ‘initializedFactory()’, I use the Object.create(arg) to create the concrete objects.