UML.5 Details of Class Definition Koichiro OCHIMIZU School of Information Science JAIST Schedule March 6th 3:00 Static Modeling (details of class specification) 4:30 Dynamic Modeling (state machine diagram, communication diagram) March 7th Case Study of Elevator Control System 3:00 Problem Definition, Use case Model) 4:30 Finding Analysis Classes by developing the consolidated communication diagram March 8th 3:00 Sub System Design 4:30 Task Design March 3th 3:00 Performance Analysis 4:30 History and Perspectives of Object Oriented Technologies A Simple model of an insurance business 0.. 0.... Customer Visibility Invoice + amount : Real + date : Date + customer : String + specification : String - administration : String + public can access it from the other classes It violates information hiding principle - private cannot access it from other classes # protected can access it from sub classes Default values Invoice + amount : Real + date : Date = Current date + customer : String + specification : String - administration : String = Unspecified Assigned at the same time an object of the class is created A class-scope attribute or a class variable Invoice + amount : Real + date : Date = Current date + customer : String + specification : String - administration : String = Unspecified - number of invoices : Integer A class variable (underlined) is shared by all objects of the class Static Modeling
Property string Invoice + amount : Real + date : Date = Current date + customer : String + specification : String - administration : String = Unspecified - number of invoices : Integer + status : Status = unpaid, paid} Property string show the possible values explicitly Java implementation public class Invoice public double amount; public Date date = new Date(); public String customer; static private int number_of_invoices = 0; // Constructor, called every time an object is created public Invoice() // Other initialization number_of_invoices++; Increment the class attribute } // Other methods go here Signature + registration number : String - data : Data + speed : Integer + direction : Direction - administration : String + drive(speed: Integer, direction: Direction) + getdata(): Data Signature: a return-type, a name, zero or more parameters Class-scope operation size : Size pos : Position figcounter : Integer getcounter(): Integer Access class-scope attributes Creation of objects Visibility of Operation size : Size pos : Position + + scale(percent: Integer = 25) + returnpos(): Position Default values of parameter size : Size pos : Position + + resize(percentx: Integer = 25, percenty: Integer = 25) + returnpos(): Position figure.resize(0,0) percentx=0, percenty=0 figure.resize(37) percentx=37, percenty=25 figure.resize() percentx=25, percenty=25 Static Modeling 2
Java implementation - x: Integer = 0 - y: Integer = 0 + public class private int x = 0; private int y = 0; public void // Java code for drawing the figure } fig = new (); fig2 = new (); fig.; fig2.; UML notations Representation of Relationships between Classes Association Navigable Association Dependency Generalization Aggregation: whole-part association Composition: the same life span G.Booch, J.Rumbaugh, I. Jacobson, The Unified Modeling Language User Guide, Addison Wesley, 999. Multiplicity A class diagram describing an business.. owns 0.. Policy 0.. owned by Company 0.. owns 0.. 0.... Customer Object Diagram Recursive Association Author name: String age: Integer 0.. Use.. Computer name: String memory: Integer Node wife husband Bob:Author Bob s PC: Computer Connects married to name = Bob J age = 32 name = Dell466 memory = 64 Static Modeling 3
Client Composite Clients use the Component class interface to interact with objects in the composite structure. If the recipient is a Leaf, then the request Is handled directly. If the recipient is a Composite, then it usually forwards requests to its child components, possibly performing additional operations before and/or after forwarding. Component Operation() Add(Component) Remove(Component) GetChild(int) children aleaf Object Diagram acomposite aleaf acomposite aleaf Leaf Operation() Composite Operation() Add(Component) Remove(Component) GetChild(int) E.Gamma, R.Helm, R.Johnson, J.Vlissides, Design Patterns, ADDISON-WESLEY, 995. forall g in children g.operation() aleaf aleaf aleaf E.Gamma, R.Helm, R.Johnson, J.Vlissides, Design Patterns, ADDISON-WESLEY, 995. Java Implementation Qualifier Company s 0.. refers to Contract Canvas // _.java file public class _ / Methods / // _Vector is a specialization of the // Vector class ensuring hard typing. Vector is a standard // Java class for dynamic arrays. private _Vector s; Canvas figure ID // _.java file public class _ / Methods / private _ refer_to one to many to one to one An insurance cannot have associations to both and person at the same time OR-association 0.. 0.. 0.... 0.... 0.. or} 0.... Company.. Company Ordered Association 0.... Customer ordered } Static Modeling 4
Association Class Ternary Association A class can be attached to an association Queue 0.. Elevator Control Button 3 Elevator The association class is not connected at any of the ends of the association policyholder 0.... 0.. policy What is an Aggregation? Aggregation Aggregation is a special case of association whole-part, is-part-of Special kinds of aggregation aggregation Shared Aggregation Composition Aggregation Navy This example is not so good. Contains Warship Aggregation Composition: The part has the same life span with the whole Shared Aggregation Composition Aggregation Team Text Members A team is composed of team members. One person could be a member of many teams. Window Listbox Button Menu Static Modeling 5
Another Expression of Aggregation Generalization Window Text Listbox Button Window Text Listbox Button Problem Fitness Vehicle Boat Property (reusability) Menu Menu Associations and Aggregation describe structure of the problem domain which we are interested in. Generalizations describe concepts which are common to several problem domains Inheritance Combination of Inheritance and Aggregation Class inheritance Interface Inheritance Canvas consists of consists of abstract} position: Pos abstract} Group Polygon consists of Line Circle Java Implementation Constrained Generalization abstract} position: Pos abstract} Group Polygon abstract public class abstract public void ; protected Pos position; public class Polygon extends public void ; / draw polygon code / Overlapping Disjoint Complete Incomplete Class B Class A constraint, constraint2,,} Class C } Static Modeling 6
Overlapping and Disjoint Complete and Incomplete Vehicle overlapping} Boat Complete} Man Woman Amphibian Refinement relationship Derivation Analysis Class Design Class hire 0.. Hire 0.. A refinement is a relationship between two descriptions of the same thing, but at different levels of abstraction. It can be also used to model different implementations of the same thing. Support Configuration Management. Support traceability In the model. / VIP customer Customer can be computed from other associations and attributes. The VIP customers are a derived association when makes s with many customers. Derived Attribute Subset Constraint Article Member of cost price sales price /profit Politician.. (subset} Party profit = sales price cost price } Party leader of Static Modeling 7
Array<,00> Template Parameterized class T, n:integer Array <<bind>><color,50> Color Array Exercise Review the content of my lecture by answering the following simple questions. Please describe the definition of each technical term.. What is a navigable association? 2. Please explain the difference of usage between association and generalization. 3. What is a dependency? 4. What is a multiplicity? 5. How can we implement many to many correspondence between objects in a program? Static Modeling 8