Escolar Documentos
Profissional Documentos
Cultura Documentos
Designing Classes
Goals
Designing classes. Designing protocols and class visibility. Defining attributes. Designing methods.
OO Design Philosophy
The first step in building an application should be to design a set of classes, each of which has a specific expertise and all of which can work together in useful ways.
In designing methods or attributes for classes, you are confronted with two issues
One is the protocol, or interface to the class operations and its visibility The other is how it should be implemented
Class visibility
Private Public Protected
Protected Protocol
Sub class
Encapsulation leakage: details about the internal implementation of a class are disclosed through the interface Impacts flexibility to accommodate future changes in implementation
Refining Attributes
In analysis phase, name of attribute was sufficient In design phase, add detailed information
Type of attributes Range of values allowed Initial values Visibility
Goals
Refine existing attributes Or add attributes to enable implementation of system
Examples:
+ names[10]:String=hello points[2..*]: Point
Add short descriptions for each attribute and also constraints if any
Attribute Types
Attribute state of an object The three basic types of attributes are:
1. Single-value attributes has one value or state
e.g, name, address
3. Reference to another object, or instance connection provide the mapping needed by an object to fulfill its
responsibilities
For example,
a person might have one or more bank accounts. A person has zero to many instance connections to Account(s). Similarly, an Account can be assigned to one or more persons (i.e., joint account). Therefore, an Account also has zero to many instance connections to Person(s).
Designing methods
Goal
Specify algorithm for methods Algorithms can be designed with the help of activity diagrams and OCL Many times pseudo code is used instead of activity diagrams Provide short textual descriptions of methods also
Return- type- expression and type- expression are language dependant specification of an implementation types If return-type omitted, no return value Eg BankClient::+verifyPassword (cardNumber: String, aPIN:String)
Move some functions into new classes that the object would use.
Apply Corollary 1 (uncoupled design with less information content).
END