Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Design Pattern & UML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 How many responsibility an object should take?
dissip

BigCat



发贴: 240
积分: 60
于 2004-05-24 18:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
How many responsibility should an object take(especially in domain modeling)?
option 1. one object should take only 1 responsibility. It seems to be pure and improve the maintainability of the system.But it will make the system full of fine grained object and make the project difficult to understand both by customer and by newer to the project.

option 2. one object for a real object in reality. that is, one object take many responsibility. it seems the object will soon get bigger and bigger. But it will provide a simple mapping between reality and system which can make the customer directly involved in the project and make all the peoples communication/understanding of the problem better.

what's your opinion?



To live is to fight.

作者 Re:How many responsibility an object should take? [Re:dissip]
guru





发贴: 131
积分: 53
于 2004-05-24 21:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I think it depends on your project's vision, resource, time etc.


作者 Re:How many responsibility an object should take? [Re:dissip]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-05-24 23:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
object composition. Use relations(generalization & various associations) to break them.

In general, I wouldn't go beyond 5. Even within 5, I still find from time to time that I could do better.



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:How many responsibility an object should take? [Re:dissip]
emarket

亢龙有诲

CJSDN高级会员


发贴: 460
积分: 82
于 2004-05-25 00:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
SRP 规定 一个 class 只应该有 一个responsibility


作者 Re:How many responsibility an object should take? [Re:dissip]
dissip

BigCat



发贴: 240
积分: 60
于 2004-05-25 09:23 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Personally I prefer option 2:one object take many responsibility. because as the complexity of software increases, the easyer it can be understood, the better. this approach can establish a evey easy relationship between entities in reality and in software world. this can make business people to get involed in the project easily and make software maintainance and evolution easy. But it seems to have its fatal problem: the object will grow rapidly and become a monolith. this will harm the maintainability at the same time.
Are the problem inherent to this approach, or are there any possible approach that could coordinate them?

by the way, what is SRP?



To live is to fight.

作者 Re:How many responsibility an object should take? [Re:dissip]
dissip

BigCat



发贴: 240
积分: 60
于 2004-05-25 09:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I agree at present option 1 will make the project managable. But i think option 2 will be the ideal approach and the future although it can not solve its problem NOW.


To live is to fight.

作者 Re:How many responsibility an object should take? [Re:dissip]
emarket

亢龙有诲

CJSDN高级会员


发贴: 460
积分: 82
于 2004-05-25 09:34 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
SRP:The Single Responsibility Principle
Agile design 得原则之一,也是refactoring 得方向

http://www.objectmentor.com/resources/articles/srp



作者 Re:How many responsibility an object should take? [Re:dissip]
dissip

BigCat



发贴: 240
积分: 60
于 2004-05-25 10:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Thank your, emarket . It seems to be a good site.
I read the article and agreed with SRP that :
a Responsibility("a reason for change”) should be encapsulated in a construct(class in current oo methodology).
But what's the result? the system will be full of small object and make the system fragmentary.
There is a old chinese saying"天下大事, 分久必合,合久比分"(I don't know whether it is its original words.)
This approach will break the system into small fragment. although each one is pure enough to be evolved easily, the system's whole is harmed.
What i say here is that,as I think, there need to be some approach that can unite these small constructs to make the system more easy to be understood by all people(business or technical) . there are some approaches now including the AOP,MDA that seems to address some part of the problem. But I think maybe a relatively fundamental different approach should be take.



To live is to fight.

作者 Re:How many responsibility an object should take? [Re:dissip]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-05-25 12:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
small objects are much much better than big combos, although both are awful in quite some cases. We can't get a perfect solution, so we choose the one next to it - small objects.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:How many responsibility an object should take? [Re:dissip]
emarket

亢龙有诲

CJSDN高级会员


发贴: 460
积分: 82
于 2004-05-25 15:41 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
dissip wrote:
there are some approaches now including the AOP,MDA that seems to address some part of the problem.


把他们搞到一起的方法就是 IOC 了
http://martinfowler.com/articles/injection.html
 



作者 Re:How many responsibility an object should take? [Re:dissip]
dissip

BigCat



发贴: 240
积分: 60
于 2004-05-26 12:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Agree with floater

As for IOC, it is a way to separating service configuration from the use of services. It does helps to link different object/component together. But it is only at implementation level and will not help to make the system clear CONCEPTUALLY.

I have some ideas about it and i will publish it after i finished it. and i hope you could share your thought then.
thanks



To live is to fight.


flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923