Imagine a scenario where I have a class with different areas of functionality:
export class TreeTable extends someOtherClass {
constructor(){
super.constructor();
}
//========= area 1 of functionality ====
itemRightClick(){this.contextMenu();}
contextMenu(){
// open file or folder context menu
}
fileContextMenu(){}
folderContextMenu(){}
//========= area 2 of functionality ====
loadData(){}
subScribeStuff(){}
unsusbscribeStuff(){}
//======== area 3 SomeOtherClasses functionality
someOtherClassMethod_1(){
this.someOtherClassMethod();
super.someOtherClassMethodTwo();
}
}
If I decide to separate and extract abstract area-1 into an external class.
class ContextMenu {
constructor(){}
//========= area 1 of functionality ====
itemRightClick(){this.contextMenu();}
contextMenu(){
// open file or folder context menu
}
fileContextMenu(){}
folderContextMenu(){}
}
export class TreeTable extends someOtherClass {
constructor(){
super.constructor();
}
//======== AREA 1
// DECORATE THIS CLASS WITH class ContextMenu AND ADD ITS METHODS
//========= area 2 of functionality ====
loadData(){}
subScribeStuff(){}
unsusbscribeStuff(){}
//======== area 3 SomeOtherClasses functionality
someOtherClassMethod_1(){
this.someOtherClassMethod();
super.someOtherClassMethodTwo();
}
}
It appears to be a straightforward task that can be achieved without using inheritance, but rather through decoration. It seems that decorators (@) are not suitable for this purpose.