Model Refinement - Quiz Explanation
The answers you selected are indicated below, along with text that explains the correct answers.
1.
What two types of behavior should be included when defining the operations for a class of objects?
Please select the best answer.
A.
External behaviors that are visible to other objects and internal behaviors that are hidden within the object and accessible only by the object itself
B.
Analysis-level behaviors that describe the way the object behaves in the problem domain and design-level behaviors that describe how the software works
C.
Behaviors that the object knows how to perform and things that other objects do to the object
D.
Interface that describes how the object talks to other objects and implementation behaviors that support the interfaces
The correct answer is C.
The two types of behavior included in a class definition are behaviors that the object knows how to perform and things that other objects do to it. A is incorrect because it differentiates based on visibility, not on functionality. B is incorrect because the problem domain class behaviors really don't change from analysis to design. Other objects, software-specific objects, are added to the model to manipulate and manage the analysis classes. D is incorrect because it simply rewords the differentiation based on visibility to other objects, not on the type of behavior.
2.
What two class elements are required in your model to manage the state of an object?
Please select the best answer.
A.
One or more attributes that describe the condition of the object and corresponding operations to maintain the attribute values
B.
An attribute that describes the state of the object and the domain of valid values that can be assigned to the status attribute
C.
One operation for each way that the object's state can be changed and a corresponding attribute for each type of change
D.
One or more attributes that describe the object's responsibility and an operation that manages the modifications to the responsibilities
The correct answer is A.
The two class elements that are required to manage the state of an object are one or more attributes that describe the condition of the object and corresponding operations to maintain the attribute values. B is incorrect because the state of an object should be defined using attributes that describe its condition. A status attribute is a common shortcut that hides the rationale behind the state changes. C is incorrect because any behavior of the object can potentially change the state of the object. State changes happen as a natural result of the object doing its job. There typically is no need to add new operations specifically to change the state of the object. D is incorrect because state does not equate to object responsibility. Furthermore, the responsibilities of an object are part of its definition as an object. They cannot (should not) ever be modified.
3.
How can you be sure that an interface is required?
Please select the best answer.
A.
Ask the users. They are the experts on how the system should perform.
B.
Model the use case scenarios as interaction diagrams and assign responsibility for each interaction.
C.
Prototype the application and test out the various scenarios, removing any unneeded interfaces until the application has only interfaces it absolutely requires.
D.
Evaluate the object cohesion to ensure that every interface supports the purpose of the object.
The correct answer is B.
The use cases describe the required functionality of the system. The interaction diagrams map that functionality to the class that represents the resources of the system. If the interface is needed to support a use case, then it is by definition required by the system. A is incorrect, though not entirely wrong. You certainly want to ask the users. But the models provide you with a much more precise method of verification than simply asking for someone's opinion. C is incorrect not because it wouldn't work, but because it is not standard and ignores the valuable resource you have in the standardized models. D is incorrect because an object may have high cohesion, but the interfaces included may be outside the scope of the project or simply not needed to solve the current problem. Again, you would be better off to go back to the use cases as your baseline requirements.
4.
How can you recognize poor cohesion in an object?
Please select the best answer.
A.
The class definition is very lengthy.
B.
Individual operations manipulate a lot of different attributes.
C.
The attributes and operations fall into distinct groups according to the function they support.
D.
There is a high degree of dependency between the object in question and other objects in the model.
The correct answer is C.
You can recognize poor cohesion in an object by looking for attributes and operations that fall into distinct groups according to the function they support. This is just an indication, not a law. Examine the groupings to see how closely they are related and how closely they support the overall purpose of the object. A is incorrect because size alone does not mean poor cohesion. Some objects are simply large. B is not entirely incorrect, but the size or complexity of an operation may be completely independent of its cohesion. However, this is a better measure of the cohesion of an individual operation than for an object. D is incorrect because it describes the test for coupling, not cohesion.
5.
How do you change the model to improve cohesion and coupling when an object appears to have too much responsibility?
Please select the best answer.
A.
Reassign responsibilities to an existing class or split the class into two or more classes with a narrower purpose.
B.
Find a design pattern that has been tested for that kind of situation.
C.
Encapsulate the object to hide the complexity from other objects.
D.
Define a separate interface for each responsibility. The new interface will delegate the responsibilities to the original interfaces.
The correct answer is A.
To improve a model with low cohesion or tight coupling, reassign responsibilities to existing classes and/or split the class into two or more classes, each with a narrower purpose. B is incorrect because it offers a solution without describing the goal of the solution. The goal is to reassign the responsibilities so that each object has a single well-defined purpose. If a pattern helps you do that, then definitely use it. C is incorrect because encapsulation does not alter the cohesion or coupling of an object. D is incorrect because the object would still contain all the same responsibilities. They would simply be hidden behind another layer of complexity.