什么是对象类型?什么是值类型? :: 人生架构
未识别博客 · wuhaixing · 2004-10-15
人生架构
人生是一个系统,越来越多的人展示他们的生活如何运行。而明天的你如何运转,执行者只能是你自己,面临的无非是任务和执行。
构建一段人生需要作出很多的选择,积累不同的组件,确定良好的结构和机制,经历不同阶段的实现....
analysis,architecture,design,developer
.:
发表评论 :.
.:
最后更新 :.
组成语言的三要素
初访Zope
自编study guide
Java Servlet & JSP Cookbook
字符串处理中的强力工具-regular expression
天哪,花了这么多时间看小说!!!
昨天以800元的价格买到了voucher
又发现了sun的优惠活动
实在不想干活,做了一上午IQ题
(值)类型的实现-flyweight 设计模式
::
<<<单音爱情故事
|
首页
|
forget login password?>>>
什么是对象类型?什么是值类型?
前段时间在javaeye学习各位Titans对于FL的讨论中
http://forum.javaeye.com/viewtopic.php?t=7878
,了解到了ValueObject(j2ee's valueObject pattern已经被改称为 transferObject pattern),但一直不是很清楚。今天终于有时间学习了UBILAB的Values in Object Systems。所以想先撇开值类型各种好处不谈,搞清楚究竟什么是对象?什么是值类型.
在Values in Object Systems中,提到了值类型和对象类型各自具有的四个特性,摘录如下:
引用:
V1-V4
・ Values are abstractions (universals or concepts) which model abstractions from a problem domain.
・ Values have no lifecycle (i.e., they do not exist in time, are not created nor changed nor deleted).
・ Values have no alterable state; representations can only be interpreted, not changed.
・ Values are referentially transparent (i.e., there are no side-effects of using a value on other parts
of the system).
值是一种抽象,它是问题域中某些抽象的模型
值没有生命周期(即不依时间存在,没有创建,没有修改也没有删除)
值没有可以修改的状态;只能对值的表达进行解释,不能改变它
值是不能
"引"用
的(即,在系统中的其他部分
使用
值不会产生副作用)
引用:
O1-O4
・ Objects are representations of phenomena from a problem domain.
・ Objects have a life cycle (i.e., they exist in time, can be instantiated, changed, and deleted).
・ Objects have identity that unambiguously denotes them (thus, they can be referenced).
・ Objects can be shared, which is a consequence of that objects can be referenced.
对象是对问题域中某些现象的表达
对象有生命周期(即他们的存在依赖于时间,可以创建实例,修改和删除)
对象有可以指定它们的明确标识(因此,可以引用它们)
因为对象可以引用,所以对象可以共享。
论文中还给出了一个地址的例子,对于一个人来说,他的居住地是一个地址,这个属性是可以改变的,但地址本身却是不能改变的。也就是说,我们在实现的时候,不是改变Address这个对象的值,而是改变inhabitAddress的引用。
所以Address应该实现为一个值类型,而不是对象类型.
wuhaixing
|
引用(trackback0)
|
编辑
□ 评论
原始快照:web.archive.org