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;
}
})
使用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;
}
})
相关文章推荐
- jscriptFrame(1) Class基类
- Android AIDL(安卓接口定义语言)基本使用方法
- flex 3 cookbook 翻译一节:定义和使用接口
- java学习路线__面向对象__接口的定义与使用__13
- error C2079: CButtonST::m_ToolTip 使用未定义的 class CToolTipCtrl
- Java接口定义以及使用(标准定义)
- C++中使用基类指针调用派生类中定义的方法
- android接口定义语言(AIDL)的使用示例
- Linux Framebuffer驱动剖析之二—驱动框架、接口实现和使用
- stm32实用技巧:JLINK接口定义和使用JTAG或SW下载程序
- JavaScript ES6的新特性使用新方法定义Class
- 微软对基类的使用手册, 觉得与现在流行的针对接口设计思想不是很合拍~~!!!
- 引用的类“Infragistics.WebUI.UltraWebTab.UltraWebTab”具有在未被引用的程序集中定义的基类或接口“Infragistics.WebUI.Shared.IUltraLicensedComponent”
- 耦合与脱耦——深入分析为什么使用pureMVC、接口或抽象基类
- 实验3_Java类的继承和接口的定义和使用
- 使用vs2008创建.net2.0时网站时,使用Ajax控件会提示:Microsoft JScript 运行时错误: 'Sys' 未定义解决方案
- C# 接口的定义和使用
- 为什么 接口只用于定义类型,不应该使用常量接口 ?
- java入门学习(11)—接口定义(interface)及使用(implements)
- setLastFrameCallFunc接口不能使用解决方案