本站首页    管理页面    写新日志    退出

The Neurotic Fishbowl

[RIA]读as3cookbook 有感
snowrose 发表于 2010/2/21 9:14:52

今天刚刚看as cookbook的第一部分,custom classes(自定义类),看到里面讲了inheritance(继承)和composite(组合),前一阵子一直听老公在我面前讲这两者的不同,今天总算看到两者的专业解释和适用的情况: "Is a" relationships are often inheritance relationships. As an example, consider an application that manages a library's collection.【“是”关系常用于表达继承关系,例如,我们认为某个应用管理着图书馆里所有的收藏】 "Has a" relationships are composition relationships in which a class declares a property. Most classes use composition. Oftentimes composition can be implemented in such a way that it achieves the same results as inheritance with greater flexibility (yet generally requiring more code). For example, a book is not an author, but it has an author (or authors).【“有”关系是把某一个类作为另一个类的某一属性的组合关系。很多类都使用这种关系。通常组合常常用于实现继承关系所能表达的含义而且更具有灵活性(但是需要相对多的代码),例如,一本书不能代表一个作者,但是书可以“有”作者(或很多作者)】The "Is a" and "Has a" test is helpful, but not always definitive in determining the relationship between classes. Often composition can be used even when inheritance would be acceptable and appropriate. In such cases the developer might opt for composition because it offers an advantage or flexibility not provided by inheritance. Furthermore, there are times when a class may appear to pass the "Is a" test yet inheritance would not be the correct relationship. For example, the library application might allow users to have accounts, and to represent the user, you would define a User class. The application might differentiate between types of users; for example, administrator and standard users. You could define Administrator and StandardUser classes. In such a case, the classes would appear to pass the "Is a" test in relation to User. It would seem to make sense that an Administrator is a User. However, if you consider the context an Administrator isn't actually a User, but more appropriately an Administrator is a role for a User. If possible, it would be better to define User so it has a role of type Administrator or StandardUser.【“是”和“有”的关系的理解比较有助但是不能全靠他们来决定如何组织类之间的关系。在继承关系会被接受或者合适的情况下,开发人员可能还会选择具有有利和灵活特征的组合关系,因为继承无法满足这两点。此外,又是当一个类以“是”的形式被传递给另一个类是,不表示这种继承是正确的。例如,图书馆应用程序里可以允许用户有帐号来表示用户,那我们会定义为一个“User”类,应用程序会把区分不同的用户;如管理员和标准用户。我们可能定义“Administrator”和“StandardUser”两个类。在某种情况下,这两类会以“是”的形式给“User”,好像看起来Administrator就是一个“User”,但是,如果你了解环境的话就明白其实不然,而“Administrator”更确切的是“User”的一种角色,或者我们可以更好的认为“User”有两种角色:“Administrator” 和“StandardUser”】   其实我觉得这本书讲的也比较细致了,其实在大谈设计模式的今天,有一类人一说oo即使继承和封装,却不知道我们需要学习和尝试的东西其实很多,本文共享给大家,相互探讨!

阅读全文(3224) | 回复(0) | 编辑 | 精华

 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

 
 



The Neurotic Fishbowl

.: 公告




Bloginess

«September 2025»
123456
78910111213
14151617181920
21222324252627
282930

.: 我的分类(专题)

首页(130)
RIA(22)
linux(3)
J2EE(24)
the mood of everyday(58)
oral English(14)
database(2)
soap(3)
java(9)
web developer center(14)


In the Bowl

.: 最新日志

倾情奉献iphone、ipod、ipho
check ipad's rotatio
css position fixed d
field validation whe
常见浏览器cookie个数和大小限制说明
人类无法抗拒的10种心理,学会它,就能控
读as3cookbook 有感
flex builder linux s
Component returned f
use tramp in emacs i


.: 最新回复

replcica watches
replcica watches
Dell spikes game sit
回复:人类无法抗拒的10种心理,学会它,
回复:人类无法抗拒的10种心理,学会它,
回复:flex builder linu
回复:人类无法抗拒的10种心理,学会它,
回复:人类无法抗拒的10种心理,学会它,
回复:致女人------摘自读者
回复:虚心接受别人的意见,谨慎改正


The Fishkeeper
blog名称:up forever
日志总数:130
评论数量:274
留言数量:4
访问次数:1948974
建立时间:2006年5月25日



Text Me

.: 留言板

签写新留言

参观
这个界面很漂亮!
我试试吧
up forever
该换了!


Other Fish in the Sea

.: 链接


http://blogger.org.cn/blog/more.asp?name=hongrui&id=16955

邢红瑞 

http://niegc.cublog.cn/  聂国聪

http://www.blogjava.net/SteelHand/ 铁手剑谱

http://blog.sina.com.cn/qianqq 糖qq

http://blog.csdn.net/misty_wish   师弟

http://www.bbxy.net/xiaoyu/ Goteet老师

http://www.chinaitpower.com    中国it动力

http://jinyuxi.blog.sohu.com/ 靳羽西




lvetica, sans-serif; MARGIN: 0px 0px 8px; PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px } DIV.blogrollmain { FONT: 12px verdana, arial, helvetica, sans-serif } BLOCKQUOTE { COLOR: #202020; FONT: 11px verdana, arial, helvetica, sans-serif } .tinyfont { FONT: 9px verdana, arial, helvetica, sans-serif } TD { COLOR: #202020; FONT-FAMILY: verdana; FONT-SIZE: 12px } .title { COLOR: #996897; FONT-FAMILY: verdana, sans-serif; FONT-SIZE: 10pt; FONT-WEIGHT: bold } .titlefont { COLOR: #996897; FONT-FAMILY: verdana, sans-serif; FONT-SIZE: 14px; FONT-STYLE: italic } .titlefontarch { BORDER-BOTTOM: 1px solid; BORDER-LEFT: 1px solid; BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; COLOR: #996897; FONT-FAMILY: verdana, sans-serif; FONT-SIZE: 14px; TEXT-ALIGN: center; WIDTH: 100% } .menu_text { COLOR: #c1ae94; FONT-FAMILY: Verdana, Arial, sans-serif; FONT-SIZE: 10px; MARGIN-BOTTOM: 1px } .links { FONT-FAMILY: Verdana, Arial, sans-serif; FONT-SIZE: 11px } .smallfont { COLOR: #202020; FONT-FAMILY: Verdana, Arial, sans-serif; FONT-SIZE: 11px; MARGIN: 0px } A:link { COLOR: #996897; TEXT-DECORATION: none } A:visited { COLOR: #996897; TEXT-DECORATION: none } A:hover { BACKGROUND-COLOR: #996897; COLOR: #610862; TEXT-DECORATION: underline } A { TEXT-DECORATION: none } .content { WIDTH: auto } .dateheader { MARGIN: 0px; PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px; POSITION: relative; WIDTH: auto; Z-INDEX: 3; min-width: 120px } .wbtn1 { BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #996897 1px solid; BORDER-LEFT: #996897 1px solid; BORDER-RIGHT: #996897 1px solid; BORDER-TOP: #996897 1px solid; COLOR: #996897; FONT-FAMILY: verdana, arial geneva; FONT-SIZE: 7pt; TEXT-DECORATION: none } .calendar { PADDING-BOTTOM: 4px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px; PADDING-TOP: 4px; TEXT-ALIGN: center } .calhead { BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: gray 1px solid; COLOR: black; TEXT-ALIGN: center; VERTICAL-ALIGN: middle; WIDTH: 14% } .calbody { BORDER-BOTTOM: 1px solid; TEXT-ALIGN: center; VERTICAL-ALIGN: middle; WIDTH: 14% } .style2 {color: #996897}
本站首页    管理页面    写新日志    退出

The Neurotic Fishbowl

[RIA]读as3cookbook 有感
snowrose 发表于 2010/2/21 9:14:52

今天刚刚看as cookbook的第一部分,custom classes(自定义类),看到里面讲了inheritance(继承)和composite(组合),前一阵子一直听老公在我面前讲这两者的不同,今天总算看到两者的专业解释和适用的情况: "Is a" relationships are often inheritance relationships. As an example, consider an application that manages a library's collection.【“是”关系常用于表达继承关系,例如,我们认为某个应用管理着图书馆里所有的收藏】 "Has a" relationships are composition relationships in which a class declares a property. Most classes use composition. Oftentimes composition can be implemented in such a way that it achieves the same results as inheritance with greater flexibility (yet generally requiring more code). For example, a book is not an author, but it has an author (or authors).【“有”关系是把某一个类作为另一个类的某一属性的组合关系。很多类都使用这种关系。通常组合常常用于实现继承关系所能表达的含义而且更具有灵活性(但是需要相对多的代码),例如,一本书不能代表一个作者,但是书可以“有”作者(或很多作者)】The "Is a" and "Has a" test is helpful, but not always definitive in determining the relationship between classes. Often composition can be used even when inheritance would be acceptable and appropriate. In such cases the developer might opt for composition because it offers an advantage or flexibility not provided by inheritance. Furthermore, there are times when a class may appear to pass the "Is a" test yet inheritance would not be the correct relationship. For example, the library application might allow users to have accounts, and to represent the user, you would define a User class. The application might differentiate between types of users; for example, administrator and standard users. You could define Administrator and StandardUser classes. In such a case, the classes would appear to pass the "Is a" test in relation to User. It would seem to make sense that an Administrator is a User. However, if you consider the context an Administrator isn't actually a User, but more appropriately an Administrator is a role for a User. If possible, it would be better to define User so it has a role of type Administrator or StandardUser.【“是”和“有”的关系的理解比较有助但是不能全靠他们来决定如何组织类之间的关系。在继承关系会被接受或者合适的情况下,开发人员可能还会选择具有有利和灵活特征的组合关系,因为继承无法满足这两点。此外,又是当一个类以“是”的形式被传递给另一个类是,不表示这种继承是正确的。例如,图书馆应用程序里可以允许用户有帐号来表示用户,那我们会定义为一个“User”类,应用程序会把区分不同的用户;如管理员和标准用户。我们可能定义“Administrator”和“StandardUser”两个类。在某种情况下,这两类会以“是”的形式给“User”,好像看起来Administrator就是一个“User”,但是,如果你了解环境的话就明白其实不然,而“Administrator”更确切的是“User”的一种角色,或者我们可以更好的认为“User”有两种角色:“Administrator” 和“StandardUser”】   其实我觉得这本书讲的也比较细致了,其实在大谈设计模式的今天,有一类人一说oo即使继承和封装,却不知道我们需要学习和尝试的东西其实很多,本文共享给大家,相互探讨!

阅读全文(3224) | 回复(0) | 编辑 | 精华

 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

 
 



The Neurotic Fishbowl

.: 公告




Bloginess

«September 2025»
123456
78910111213
14151617181920
21222324252627
282930

.: 我的分类(专题)

首页(130)
RIA(22)
linux(3)
J2EE(24)
the mood of everyday(58)
oral English(14)
database(2)
soap(3)
java(9)
web developer center(14)


In the Bowl

.: 最新日志

倾情奉献iphone、ipod、ipho
check ipad's rotatio
css position fixed d
field validation whe
常见浏览器cookie个数和大小限制说明
人类无法抗拒的10种心理,学会它,就能控
读as3cookbook 有感
flex builder linux s
Component returned f
use tramp in emacs i


.: 最新回复

replcica watches
replcica watches
Dell spikes game sit
回复:人类无法抗拒的10种心理,学会它,
回复:人类无法抗拒的10种心理,学会它,
回复:flex builder linu
回复:人类无法抗拒的10种心理,学会它,
回复:人类无法抗拒的10种心理,学会它,
回复:致女人------摘自读者
回复:虚心接受别人的意见,谨慎改正


The Fishkeeper
blog名称:up forever
日志总数:130
评论数量:274
留言数量:4
访问次数:1948974
建立时间:2006年5月25日



Text Me

.: 留言板

签写新留言

参观
这个界面很漂亮!
我试试吧
up forever
该换了!


Other Fish in the Sea

.: 链接


http://blogger.org.cn/blog/more.asp?name=hongrui&id=16955

邢红瑞 

http://niegc.cublog.cn/  聂国聪

http://www.blogjava.net/SteelHand/ 铁手剑谱

http://blog.sina.com.cn/qianqq 糖qq

http://blog.csdn.net/misty_wish   师弟

http://www.bbxy.net/xiaoyu/ Goteet老师

http://www.chinaitpower.com    中国it动力

http://jinyuxi.blog.sohu.com/ 靳羽西




站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.185 second(s), page refreshed 144760902 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号