Skip to content

Add ability to declare methods as 'final' #5

Description

@gregjacobs

To support some more advanced frameworks in class hierarchies.

For example, something very similar to the following situation arose for a Task class in my work one day:

var Task = Class.create( {
    abstractClass: true,

    execute : function() {
        if( this.executing ) return;
        this.executing = true;

        this.doExecute();  // call hook method
    },

    doExecute : Class.abstractMethod
} );

var RequestTask = Task.extend( {
    abstractClass: true,

    doExecute : function() {
        var request = this.createRequest();

        request.execute().then(
            _.bind( this.onSuccess, this ),
            _.bind( this.onError, this )
        );
    },

    createRequest : Class.abstractMethod,

    onSuccess : function() {...},
    onError : function() {...}
} );

In the above example, we do not want to allow doExecute() to be redefined by a subclass of RequestTask.

Only createRequest() should be implemented to create and configure a Request object that the RequestTask will execute.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions