RoleAssigner类的理解疑惑

,这里面机器人的例子还好理解,
public String hello(String id) {
Robot robot = robotRepository.find(id);
//将角色智能机器人IntelligentRole的行为注入到Robot数据对象中
IntelligentRole intelligentRobot = (IntelligentRole) roleAssigner.assign(robot, new IntelligentRobot());
//得到一个混和robot将具有听 看 感觉等能力行为
return "Hello, " + intelligentRobot.hear();
}
把智能的属性附加到之前的robot上,roleAssigner名副其实就是角色助手的作用。不过还不够彻底,因为不能将intelligentRobot向下转型为Robot,即(Robot)intelligentRobot来调用Robot的方法。

再看SimpleJdonFrameworkTest项目,ResourceManagerContext类里面的update方法
@Path("/user")
@PUT
public Represent update(UserModel user) {
UserModel userold = getUser(user.getUserId());
if (userold == null)
return new State("/");

userold.update(user);

// here is for client's load
ComputeContext computeContext = new ComputeContext();
computeContext.preloadData(userold);
RepositoryManagerIF rm = (RepositoryManagerIF) roleAssigner.assign(userold, new RepositoryManagerEventImp());
rm.remember(userold);
return new State("/");
}
其中的
RepositoryManagerIF rm = (RepositoryManagerIF) roleAssigner.assign(userold, new RepositoryManagerEventImp());
rm.remember(userold);
是将角色RepositoryManagerEventImp,赋予userold,但为何在remember中又要讲userold作为参数呢。
按理说应该直接rm.remember就好了呀。如果说像代码中的写法完全可以绕开roleAssigner,直接new一个RepositoryManagerEventImp不就完了么?
这样的写法是否是由于面向对象的技术限制呢?

2012年02月13日 10:02 "@liuyf"的内容
这样的写法是否是由于面向对象的技术限制呢 ...

根据不同场景进行注射,参考这篇文章:DCI Role Injection in Ruby,文章对比了使用接口 或委托等传统OO实现与DCI注入的区别。
[该贴被banq于2012-02-13 11:12修改过]
[该贴被banq于2012-02-13 11:14修改过]