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

anti-pattern for abstract types #189

Closed
pixelzoom opened this issue Nov 9, 2015 · 2 comments
Closed

anti-pattern for abstract types #189

pixelzoom opened this issue Nov 9, 2015 · 2 comments
Assignees

Comments

@pixelzoom
Copy link
Contributor

Related to code review #173.

ModeConfig is intended to be an abstract base type, so the first thing would be to describe it as such in the JSdoc at the top of the file.

Then there's this function that must be implemented by subtypes:

    // abstract
    /**
     * @returns {Array<BodyConfiguration}
     */
    getBodies: function() {}

This pattern is not recommended because (in the general case) it can succeed silently when it should fail.

The more typical pattern for functions in abstract types is to either (a) not define them so that they fail, or (b) implement a function that fails. My preference is for (b), since it also provides the opportunity to document. So recommended to replace the above with:

    /**
     * @returns {BodyConfiguration[]}
     * @public
     * @abstract
     */
    getBodies: function() {
      throw new Error( 'must be implemented by subtype' );
    }
@aaronsamuel137
Copy link
Contributor

I've made these changes, assigning to @pixelzoom for review.

@pixelzoom
Copy link
Contributor Author

👍 Closing.

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

No branches or pull requests

3 participants