Fake Objects
2016-05-31 11:11
399 查看
Spring的创始人Rod Johnson关于伪对象:
Fake Objects: objects in appearance, but which don’t exhibit some of the characteristics of objects:
identity, state, and behavior。
Let’s look at some common fake objects and why to avoid them if possible:
❑ Transfer objects, often referred to as Data Transfer Objects (DTOs) or Value Objects. Transfer
objects are not true objects because they contain only state, without behavior. Transfer objects
are a necessary evil in distributed applications (although there’s an argument that this kind of
data should really be included in an XML structure rather than Java objects). But if we don’t
want a distributed architecture, they’re redundant and harmful, creating an unwelcome
impedance mismatch between business services and callers.
❑ Entity beans or other persistent objects generated from RDBMS tables. These reflect a relational,
rather than OO, model. They have a harmful effect on code that works with them, which
is forced to navigate relationships and cannot benefit from OO concepts such as polymorphism.
There’s also inadequate decoupling between business logic and persistent data representation.
❑ Persistent objects in general that contain only getters and setters, without behavior. Such fake
objects force behavior that they should encapsulate to be moved into control classes such as session
beans. Not only is encapsulation violated, but the result tends to be verbose code in control
classes.
UI+BLL+DAL+Model 是当前最常用的企业级开发的三层架构。但通常BLL层弱化为控制部分,即业务对象只有行为无状态,而Model层弱化为数据库的持久化表示,即只有状态而无行为。DAL变为BLL和DB的中介,而媒介就是Model。
如何由伪对象过度到真正的OO? 创建真正的BO,即有行为又有状态,这样就取消了Model层。
Fake Objects: objects in appearance, but which don’t exhibit some of the characteristics of objects:
identity, state, and behavior。
Let’s look at some common fake objects and why to avoid them if possible:
❑ Transfer objects, often referred to as Data Transfer Objects (DTOs) or Value Objects. Transfer
objects are not true objects because they contain only state, without behavior. Transfer objects
are a necessary evil in distributed applications (although there’s an argument that this kind of
data should really be included in an XML structure rather than Java objects). But if we don’t
want a distributed architecture, they’re redundant and harmful, creating an unwelcome
impedance mismatch between business services and callers.
❑ Entity beans or other persistent objects generated from RDBMS tables. These reflect a relational,
rather than OO, model. They have a harmful effect on code that works with them, which
is forced to navigate relationships and cannot benefit from OO concepts such as polymorphism.
There’s also inadequate decoupling between business logic and persistent data representation.
❑ Persistent objects in general that contain only getters and setters, without behavior. Such fake
objects force behavior that they should encapsulate to be moved into control classes such as session
beans. Not only is encapsulation violated, but the result tends to be verbose code in control
classes.
UI+BLL+DAL+Model 是当前最常用的企业级开发的三层架构。但通常BLL层弱化为控制部分,即业务对象只有行为无状态,而Model层弱化为数据库的持久化表示,即只有状态而无行为。DAL变为BLL和DB的中介,而媒介就是Model。
如何由伪对象过度到真正的OO? 创建真正的BO,即有行为又有状态,这样就取消了Model层。
相关文章推荐
- iOS开发系列—Objective-C之内存管理
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- iOS objection 依赖注入
- NSObject
- C++: Iterating through all of an object's members? C++遍历成员变量
- Objective-C ---UIButton (梳理整理)
- STL--Function Objects(一)
- Objective-C 编程全解-第02章 Objective-C程序设计
- 关于object类的两个重要方法以及为什么重写equals一定要重写hashcode()
- READING NOTE: Semantic Object Parsing with Graph LSTM
- SNMP++ 04-SNMP中OBJECT IDENTIFIER的BER编码与解码及一些思考
- 关于EnumerateObjectsUsingBlock和for-in之间的较量
- Objective-C 编程全解-第01章 面向对象的编程
- Windows内核开发中如何区分文件对象究竟是文件还是文件夹?(FILE_OBJECT包括了无数详细信息)
- java和objective-C对接笔记
- Objective-C的动态特性
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Objective-c中@interface、@implementation、@protocal
- Objective-C中系统预留的Debug表达式
- queryset object has no attribute meta