Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorator Pattern extend() #222

Open
iramirezc opened this issue Jun 9, 2019 · 1 comment
Open

Decorator Pattern extend() #222

iramirezc opened this issue Jun 9, 2019 · 1 comment

Comments

@iramirezc
Copy link

Hi Addy,

I wonder why in this line of code

we are extending CaseDecorator with MacbookDecorator. As functions, they don't have any enumerable properties by their own yet. Shouldn't happen the extension in the prototype like:

extend(CaseDecorator.prototype, MacbookDecorator.prototype);

because trying to do this console.log(decoratedMacbookPro.addEngraving()); results in a TypeError: decoratedMacbookPro.addEngraving is not a function

@iramirezc
Copy link
Author

Also, in this constructor:

shouldn't CaseDecorator be a "subclass" of MacbookDecorator as we learned from the Mixins Pattern:

var CaseDecorator = function( macbook ){
   MacbookDecorator.call(this, macbook)
};

That way, when doing

var decoratedMacbookPro = new CaseDecorator( myMacbookPro );
we are ensuring that the MacbookPro instance fulfills the required interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant