Modifying an existing design pattern to fit different use cases
Patterns are not commandments received from a higher plane. They have their origins in, and have been refined from, real-world engineering projects. Patterns can be modified to fit new situations better.
In this recipe, we'll see how to modify the factory pattern to make creating missions easier.
Getting ready
This recipe assumes you already have a workspace that allows you to create and run ES modules in your browser. If you don't, please see the first two chapters.
How to do it...
- Open your command-line application and navigate to your workspace.
- Create a new folder named
09-06-modifying-existing-design-pattern-to-fit-differet-use-cases
. - Copy or create an
index.html
that loads and runs amain
function frommain.js
. - Create a
main.js
file that defines a newclass
namedMission
. Add a constructor that takes aname
constructor argument and assigns it to an instance property. Also, define a simpleprint
method:
// main.js class Mission...