请注意 ......
misoo对象技术顾问团队.对象导向杂志作者.等. 【程序编程相关:vs.netbeta2中利用DataGr】著作权所有人:物泽计算机事业股份有限公司. 【推荐阅读:COM组件对象与.NET类对象的相互转换】u本文件仅供您的参阅,请遵守著作权法,不得做其它商业用途. 【扩展信息:在你的VB.NET应用程序中使用多线程】u本文件摘自 对象导向杂志.精通对象观念与技术等书籍著作.
主题: 类别与封装性(ecapsulation)
???????????? 内容 ????????????
v 1. 类别的「程序成员」v 2. 「封装性」概念1. 类别的「程序成员」(procedure member)
类别 (class)之任务是把资料(data)与程序(procedure)组织并封装起来.类别告诉计算机﹕「其对象应含有那些资料.应含有那些程序裨处理外界传来之讯息」.类别须详细说明它的资料及程序﹐我们称此资料是类别之「资料成员」(data member) ﹔而称此程序是类别之「程序成员」(procedure member).有关类别内容之叙述﹐就是所谓的类别定义(class definition).类别定义之格式为──
类别之用途为﹕宣告对象.例如﹕ex01.bas
imports system.componentmodelimports system.drawingimports system.winforms----------------------------------------------------class tree public varity as string public age as integer public height as singleend class-----------------------------------------------------public class form1 inherits system.winforms.form public sub new() mybase.new() form1 = me this call is required by the win form designer. initializecomponent() todo:add any initialization after the initializecomponent() call end sub form overrides dispose to clean up the component list. public overrides sub dispose() mybase.dispose() components.dispose() end sub#region " windows form designer generated code " .......#end region protected sub form1_click(byval sender as object, byval e as system.eventargs) dim a as new tree() msgbox("object a is created.") end sub end class此程序定义了类别tree﹐它只含资料而无程序﹐为一「阳春型」之类别.当计算机执行到form1_click()程序内之宣告指令──
dim a as new tree()就分配足够存放这 3项资料的内存空间给予对象 a.然而﹐此tree类别只有资料而无程序.所以﹐对象 a无法接受外来之讯息.此时﹐可加入程序成员﹐使tree类别含有程序.具有动力﹐对象就有能力来处理讯息了.例如﹕
... 下一页