jeudi 31 décembre 2020

Implementing delegation in decorator pattern

How can I delegate calls to the wrapped object - other than the functionality I changed:

class Base {
   function doSomething {}
   function doOtherSomething {}
   function doOtherSomething2 {}
}

class Decorator {
   constructor(wrapped) {
      this.wrapped = wrapped;
   }

   function doSomething { 
       console.log("doing more stuff");
       this.wrapped.doSomething()}
    }
}

How do I delegate the other functions to automatically be called on the Base class?

Aucun commentaire:

Enregistrer un commentaire