Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Designing classes
UML object constraint language UML graphical language with a set of rules and semantics. The rules and semantics are of the UML are expressed in English , in a form known as object constraint language (OCL) OCL It is a specification language that uses simple logic for specifying the properties of a system.
Item.selector selector is the name of an attribute in the item. John.age Item.selector[qualifier-value] john.phone[2] Set->select(boolean-expression) company.employees->salary>30000
Designing classes: the process 1.Apply design axioms to design classes,their attributes,methods,associations,structuresand protocols. 1.1 Refine and complete the static UML class diagram by adding details to that diagram. 1.1.1 Refine attributes 1.1.2 Design methods and the protocols by utilizing a UML activity diagram to represent the methods algorithm. 1.1.3 Refine the associations between class(if required) 1.1.4 Refine the class hierarchy and design with inheritance (if required) 1.2 Iterate and refine.
Visibility
A class might have a set of methods that it uses only internally, messages to itself. This private protocol of the class, includes messages that normally should not be sent from other objects. Here only the class itself can use the methods. The public protocol defines the stated behavior of the class as a citizen in a population and is important information for users as well as future descendants, so it is accessible to all classes. If the methods or attributes can be used by the class itself (or its subclasses) a protected protocol can be used. Here subclasses can used the method in addition to the class itself. The lack of well-designed protocol can manifest itself as encapsulation leakage. It happens when details about a classs internal implementation are disclosed through the interface.
Attributes
Attributes represent the state of an object. When the state of the object changes, these changes are reflected in the value of attributes. Single value attribute has only one value or state. (Eg). Name, address, salary Multiplicity or multivalue attribute can have a collection of many values at any time. (Eg) If we want to keep tact of the names of people who have called a customer support line for help.
UML attribute presentation visibility name : type-expression=initial-value Where visibility is one of the following: + Public visibility(accessibility to all classes) # Protected visibility(accessibility to subclasses and operations of the class) - Private visibility(accessibility only to operations of the class) type-expression is a language-dependent specification of the implementation type of an attribute initial-value is a language-dependent expression for the initial value of a newly created object. It is optional Example: +size:length = 100
Five rules If it looks messy,then its probably a bad design If it is too complex,then its probably a a bad design. If it is too big,then its probably a a bad design. If people dont like it ,then its probably a a bad design. If it doesnt work,then its probably a a bad design.
Design issues: avoiding pitfalls 1.Keep a careful eye on the class design and make sure that an objects role remains well defined. 2.Move some functions to new classes that the object would use. 3.Break up the class into two or more classes. 4.Rethink the class definition based on experience gained.