标签:
Modeling the Distribution of Responsibilities in a System
为系统的职责分配建模
Once you start modeling more than just a handful of classes, you will want to be sure that your abstractions provide a balanced set of responsibilities. What this means is that you don’t want any one class to be too big or too small. Each class should do one thing well. If you abstract classes that are too big, you’ll find that your models are hard to change and are not very reusable.if you abstract classes that are too small, you’ll end up with many more abstractions than you can reasonably manage or understand. You can use the UML to help you visualize and specify this balance of responsibilities.
一旦开始建模,你就不仅仅是考虑那些类,还要确保你的抽象事物提供职责集合的平衡.这指的是你不希望任何一个类太大或是太小.每个类应该做好一件事.如果你的抽象类太大,你会发现你的模型将很难改变并且不可重复使用.如果你的抽象类太小,你会有更多的抽象事物,这将让你难以合理地管理或理解.你能使用UML来帮助你可视化和描述这些职责的平衡.
To model the distribution of responsibilities in a system,
在系统中为职责的分配建模,
1. Identify a set of classes that work together closely to carry out some behavior
为执行一些行为而识别一组密切合作的类
2. Identify a set of responsibilities for each of these classes.
为这些类中的每个标识一组职责
3. Look at this set of classes as a whole, split classes that have too many responsibilities into smaller abstractions, collapse tiny classes that have trivial responsibilities into larger ones, and reallocate responsibilities so that each abstraction reasonably stands on its own.
将有太多职责的类划分成更小的抽象事物,削减微小的类,将其不太重要的职责加到更大的类中,并重新分配职责,以便每个抽象有清晰的独立性.
4. Consider the ways in which those classes collaborate with one another and redistribute their responsibilities accordingly so that no class within a collaboration does too much or too little.
考虑如何让那些类与其它的类交互,考虑重新分配它们的职责以便在协作中的类不会太多或是太少.
For example, Figure 4-10 shows a set of classes drawn from Smalltalk, showing the distribution of responsibilities among Model, View, and Controller classes. Notice how all these classes work together such that no one class does too much or too little.
举个例子,如图4-10显示的来自SmallTalk的一组类,显示的是在模型,视图和控制器三个类之间的职责分配.注意所有这些类是如何一起工作,这些没有一个类的职责太多或太少.
标签:
原文地址:http://blog.csdn.net/listen_snow/article/details/42639589