Combining existing design patterns to fit different use cases
Modifying and extending patterns doesn't mean that we must forge ahead into terra incognita. It is still advisable to use well-known patterns when tackling new problems.
In this recipe, we'll see how to combine two patterns to better fit a given use case.
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-07-combine-design-patters-to-fit-new-use-case. - Copy or create an
index.htmlthat loads and runs amainfunction frommain.js. - Create a
main.jsfile that defines a newclassnamedMission. Create a constructor that assigns anameargument to an instance variable. Add a simpleprintfunction:
// main.js
class Mission {
constructor (name) {
this.name = name;
}
describe () {
console.log...