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

proposal for class-level refinement #17

Open
hiun opened this issue Sep 17, 2017 · 1 comment
Open

proposal for class-level refinement #17

hiun opened this issue Sep 17, 2017 · 1 comment

Comments

@hiun
Copy link
Owner

hiun commented Sep 17, 2017

Motivation

Refinable Functions focuses on function-level refinement, however implicit augmentation of method in classes is essential for implementing aspect-orientation. This idea requires 2 new mechanism of refinement.

1.Refinable Functions as a Advice

Advices is class of function that modifies other function when run. It is a certain function, method or procedure that is to be applied at a given join point of program,(wikipedia). The join point is represented in keyword like before, after and around in typical aspect-orientation, where as point cut represent point of join point composition. I propose following syntax for export Refinable Function as ann Advice

subjectChangeAdvice.export.before('subjectChange');
subjectChangeAdvice.export.after('subjectChange');
subjectChangeAdvice.export.around('subjectChange');

In this sense, function refinement and class refinement is performed in two phase.

2.Class-level Refinement with Aspect-oriented Programming

Aspect-oriented Programming towards localization of cross-cutting concerns using aspect object that augment a behavior of method. The aspect object itself can be inheritable, for example the following codes is aspect for ObserverProtocol.

var ObserverProtocolAspect = {

  perSubjectObservers: new WeakMap(),
  getObservers: function (subject) {
    
    observers = this.perSubjectObservers.get(subject);
    
    if (observers == null) {
      perSubjectObservers.put(subject, []);
    }
    return observers;
  },

  addObserver: function (subject, observer) {
    getObservers(subject).add(observer);
  },

  removeObserver: function (subject, observer) {
    getObservers(subject).remove(observer);
  },

  //subjectChange: null,
  //below method implicies subject change is required field for its subaspect

  subjectChange: new Self().add(inputCheck).add(function (subject, observer) {
    return this.updateObserver(subject, observer)
  }).export.before()

};

var ObserverProtocol = new Self.utils.aspect(ObserverProtocolAspect);

and by extending ObserverProtocol aspect, we can make more concrete subaspect called ColorObserver using .extends method.

//interception instead of composition
var ColorObserver = {
  subjectChange: function subjectChange(subjectChange) {
    return {
      setColor: subjectChange,
      setLine: subjectChange
    }
  },
  updateObserver: function (subject, observer) {
    //type is needed
    //fault of dynamic type checking => static typechecking and aspect weaving make weaving reliable
    //type system make aspect weaving safe and deterministic
    //
    this.display("color updated")
  }
}

var ColorObserver = new Self.utils.aspect(ColorObserver);
ColorObserver.extends(ObserverProtocol);
//member variable manipulation, function manipulation
ColorObserver.compose(className);
@hiun
Copy link
Owner Author

hiun commented Sep 28, 2017

pass host object to subjectChange when obj.setColor is invoked

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

1 participant