27-10-2012, 04:22 PM
Object Design:Specifying Interfaces
Object Design.pdf (Size: 345.59 KB / Downloads: 30)
Requirements Analysis vs. Object Design
•Requirements Analysis:The functional model and the dynamic model deliver operations for the object model
•Object Design: Decide where to put these operations in the object model
•Object design is the process of
•adding details to the requirements analysis
•making implementation decisions
•Thus, object design serves as the basis of implementation
•The object designer can choose among different ways to implement the system model obtained during requirements analysis.
Add Visibility Information
Class user (“Public”):
•Public attributes/operation can be accessed by any class
Class implementor (“Private”): -
•Private attributes and operations can be accessed only by the class in which they are defined
•They cannot be accessed by subclasses or other classes
Class extender (“Protected”):
•Protected attributes/operations can be accessed by the class in which they are defined and by any descendent of the class.
Information Hiding Heuristics
•Carefully define the public interface for classes as well as subsystems
•For subsystems use a façade design pattern if possible
•Always apply the “Need to know” principle:
•Only if somebody needs to access the information, make it publicly possible
•Provide only well defined channels, so you always know the access
•The fewer details a class user has to know
•the easier the class can be changed
•the less likely they will be affected by any changes in the class implementation
•Trade-off: Information hiding vs. efficiency
•Accessing a private attribute might be too slow.
Modeling Constraints with Contracts
•Example of constraints in Arena:
•An already registered player cannot be registered again
•The number of players in a tournament should not be more than maxNumPlayers
•One can only remove players that have been registered
•These constraints cannot be modeled in UML
•We model them with contracts
•Contracts can be written in OCL.