关闭

Fake Objects

123人阅读 评论(3) 收藏 举报
分类:

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层。



0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:115335次
    • 积分:2359
    • 等级:
    • 排名:第15721名
    • 原创:124篇
    • 转载:29篇
    • 译文:0篇
    • 评论:259条
    文章分类
    最新评论