您的位置:首页 > Web前端 > JavaScript

jscriptFrame(2) 使用Class基类定义接口

2008-02-08 11:19 363 查看
接口是OO中重要的实现方法,可以实现对相似业务逻辑的抽象,是“解耦合”原则实现的重要途径之一。

使用Class基类可以实现“接口”。




var Interface = Class.extend(...{


construct:$abstract;


methordA:$abstract;


methordB:$abstract;


})


Interface.implement = Interface.extend;

ClassA “实现” Interface 接口:




var ClassA = Interface.implement(...{




construct:function()...{


this.p1 = 1;


this.p2 = 2;


},




methordA:function()...{


return this.p1 - this.p2;


},




methordB:function()...{


return this.p1 + this.p2;


}


})

ClassB 也“实现” Interface 接口:




var ClassB = Interface.implement(...{




construct:function()...{


this.p1 = 1;


this.p2 = 2;


},




methordA:function()...{


return this.p1 * this.p2;


}




methordB:function()...{


return this.p1 / this.p2;


}


})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: