接口是OO中重要的實現方法,可以實現對相似業務邏輯的抽象,是“解耦合”原則實現的重要途徑之一。
使用Class基類可以實現“接口”。
construct:$abstract;
methordA:$abstract;
methordB:$abstract;
})
Interface.implement = Interface.extend;
construct:function(){
this.p1 = 1;
this.p2 = 2;
},
methordA:function(){
return this.p1 - this.p2;
},
methordB:function(){
return this.p1 + this.p2;
}
})
construct:function(){
this.p1 = 1;
this.p2 = 2;
},
methordA:function(){
return this.p1 * this.p2;
}
methordB:function(){
return this.p1 / this.p2;
}
})