470 likes | 776 Views
Introduction to Unified Modeling Language (UML). By Mercer & Milanova, updated by Professor Spiegel, with help from The Unified Modeling Language User Guide , Grady Booch, James Rumbaugh, Ivar Jacobsen , Addison Wesley, 1999, ISBN 0-201-57168-4. play(). roll(). fv1:=getFaceValue().
E N D
Introduction to Unified Modeling Language (UML) By Mercer & Milanova, updated by Professor Spiegel, with help from The Unified Modeling Language User Guide, Grady Booch, James Rumbaugh, Ivar Jacobsen , Addison Wesley, 1999, ISBN 0-201-57168-4
play() roll() fv1:=getFaceValue() fv2:=getFaceValue() roll() Models • Use Case: Process Sale • Main Success Scenario • Customer arrives with … • Cashier … • … • Extensions: • 3a. … Dice Game...
UML • UML - Unified Modeling Language • Standard for diagramming notation • Just a notation, not a methodology or process • Important • …but not as important as analysis and design patterns
The Unified Modeling Language (UML) • UML or Unified Modeling Language comes from Rumbaugh, Booch, and Jacobson, who combined efforts to standardize on one modeling language • This is primarily a graphical communication mechanism for developers and customers
UML • The main purpose of UML is to • support communication about the analysis and design of the system being developed • support the movement from the problem domain in the "world" to the solution domain in the machine • two views of the same system • one view has diagrams • source code is another view
UML Defined by the Authors The Unified Modeling Language User Guide, Booch, Rumbaugh, Jacobson states: The UML is a language for • visualizing • specifying • constructing • documenting the artifacts of a software intensive system
UML is a Modeling Language • UML • graphical notation to describe software design • has rules on how to draw models of • classes • associations between classes • message sends between objects • has become the de facto industry standard • Not official, but everyone uses it • Like a blueprint to show what is going on during analysis, design and implementation • Some Projects require UML documentation
Designer Goals • Simpler UML within general comprehensive UML • Usefulness in several modeling perspectives - design, analysis, etc. • Correspondence to code • Computer aided as well as manual usage
Class Diagrams • A class diagram • expresses class definitions to be implemented • lists name, attributes, and methods for each class • shows how instances will connect to others • UML allows different levels of detail on both the attributes and the methods of one class • could be just the the class name in a rectangle • or like the general form shown on the next slide
Classes, Attributes and Operations AClass AClass attributes operations Obj : AClass Obj : AClass
Attributes • Information about the object • Is it synonymous with a variable? • Yes, most of the time • Sometimes needs manipulation • Derived from other attributes • Gettable and settable • Read-only • Notation for attributes: visibility name: type = initialValue <<sterotype>> (see slide 16 for <<stereotype>>)
Methods/Operations • Set and get methods for attributes • Methods often have input arguments • Communicate with other objects • Notation for methods: visibility name(param1: type1,…) : returnType <<stereotype>>
Attributes and Methods • Visibility: + public, # protected, - private, ~ package AClass • Class attributes andmethods + publicAttr: Class1# protectedAttr: Class2- privateAttr: Class3 ~ packageAttr: Class4 + publicOperation()# protectedOperation()- privateOperation() ~ packageOperation()
Software Specification (Class Name) attribute attribute : type attribute : type = initial value classAttribute derivedAttribute ... method1() method2(parameter : Type) : return type abstractMethod() +publicMethod() -privateMethod() #protectedMethod() classMethod() ...
AccountCollection - allAccounts : HashMap +AccountCollection () +getAccountWithID (ID: String) : Account +add(accountToAdd: Account) : boolean +iterator() : Iterator Note: iterator is needed by the bank manager
Sterotypes • Stereotype is a UML element that allows designers to extend the UML vocabulary • Often used to distinguish an abstract class name from an interface, both of which are written in italic <<interface>> Iterator +hasNext(): boolean +next(): Object +remove(): void
UML Stereotype vs. UML property • Stereotype, e.g., <<utility>> • Represents a new modeling construct • Property, e.g., {abstract} • Represents a characteristic of an existing UML construct, for example a class can be abstract, or immutable • E.g., characteristics of classes Polygon{abstract} << utility >>SymbolTable
Parameterized Classes (Templates) T Set T Set <<bind>> <car> Fleet Set<Car> Fleet= Set<Car>
Different levels of detail • Tips for modeling • Express as much or as little detail as needed • Often, a rectangle with a name is enough • perhaps a method or an attribute clarifies • Simple is good • Sketches on paper or white board are effective
Relationships • Three Relationships in UML 1) Dependency 2) Association 3) Generalization • Understanding these relationships is more important than the lines that UML uses
1) Dependency: A Uses Relationship • Dependencies • occurs when one object depends on another • if you change one object's interface, you need to change the dependent object • arrow points from dependent to needed objects CardReader Jukebox CDCollection SongSelector
2)Association: Structural Relationship • Association • a relationship between classes indicates some meaningful and interesting connection • Can label associations with a hyphen connected verb phrase which reads well between concepts association getAccountWithID Jukebox JukeboxAccountCollection 1 1
Associations • Associations imply • our knowledge that a relationship must be preserved for some time (1 ns to forever?) • Between what objects do we need to remember a relationship? • Does a Transaction need to remember Account? • Would AccountCollection need to remember Accounts? Stores AccountCollection Account 1 1..*
Notation and Multiplicity Adornments • UML Association: • a line between two concepts and a name • they are bi-directional • can have a multiplicity • exist in class diagrams zero or more; * T "many" * 1.. T one or more 1..52 T one to fifty two 5 Multiplicity adornments T exactly five 3, 5, 8 exactly three, T five or eight
Multiplicity • Multiplicity defines how many instances of type A can be associated with one instance of type B at some point can differ Game Player 1 2..6 Mother Child 1 1+ Actor is associated with 0 to many films. A film is associated with 0 to many actors performs-in Actor Film * * can label associations
Depends on Context • Are all three associations possible? Car Wheel 1 4 Car Wheel 5 1 Car Wheel 1 3
Association Names Upcase / hyphenate • Read this Type-VerbPhrase-Type (POST is a Point of Sale Terminal) • Not yet worrying about messages, instance variables, data flow, or classes yet • Just shows which objects have associations
Class Diagrams • Static structure of the classes of objects • Three important OO constructs • Inheritance • Association • Part/whole structure
Inheritance: is-a • The generalization construct • Disjoint vs. overlapping • Disjoint – single member cannot belong to both B and C • Incomplete vs. complete • Incomplete – there are members of A that are not members of either B or C • Dynamic vs. static • Dynamic – over time a member of B can become a member of C A {disjoint,complete} B C • Subclass partitioning
Subclass Partitioning, Examples Disjoint (No airplane can be a car), incomplete (Trucks are powered vehicles too)hierarchy PoweredVehicle Airplane Car Employee Disjoint (No employee can be a manager and non-manager at the same time), complete (There are no other kinds of employees),and dynamic (a non-manager can become a manager and vice versa)hierarchy Manager Non-Manager
Multiplicities Meaning 0..1 zero or one instance. The notation n . . m indicates n tom instances. 0..*or* no limit on the number of instances (including none). 1 exactly one instance 1..* at least one instance More Associations • Varying populations of relationships between instances of classes • Navigability • Multiplicity 1 * Dog ownership Person Dog
StudentNameAddressPhone NumberEmail AddressStudent NumberAverage GradeIs Eligible To EnrollProvide Seminars Taken Seminar NameSeminar NumberFeesAdd StudentDelete Student Class Diagrams enrolled Enrollment Marks ReceivedProvide Avg to Date Provide Final Grade 1..* 1 1 1..* in 0..* on waiting list 0..* Student- name: string- phoneNumber: PhoneNumber…+isEligible(name:string, studentNumber: StudentNumber): bool+Student(studentNumber: StudentNumber):Student <<constructor>>+getAverageGrage():long+provideSeminarsTaken():Vector
Some Problems: Modeling Whole/Part Associations • Composition • E.g., Glider has a component Tail • Composite object is the whole • Component is the part • Composite cannot exist without component • A component part of only one composite • Stronger: composite should create component • Stronger: if delete component, composite goes away too, i.e., cascading delete • Typically components of different kinds
Whole/Part Associations • Aggregation, weaker than composition • E.g., Cityis an aggregate of houses • Aggregate is the whole • Constituent is the part • Aggregate may exist without constituents • Each object may be part of more than one aggregate • Typically, constituents are of same class
Composition vs. Aggregation • In real world there are 7 or 8 varieties of whole/part relationships, but UML has only two constructs – composition and aggregation • Can be very difficult, and confusing to choose one
Aggregation: A Special Association • Aggregation: whole/part relationships • An association that models HAS-A relationships • The objects can exist independently or each other • No one object is more important than the other • Place an open diamond on the whole • Could mean School has a HashMap of Students School Student 1..* *
Composition: A Special Association • Composition: Stronger relationship • One can not exist without the other • If the school folds, students live on • but the departments go away also • If a department closes, the school can go on AIC e.g. • Model aggregation or composition? When in doubt, use association (just a simple line) School Department 1 1..* 1..* * Student
Composition vs. Aggregation Examples • Class and students • Class is whole, students are parts • The class can exist without students (e.g., a class with 0 enrollment) • A student may be part of more than one class • Parts are of same kind (students) • What is it?
Examples, cont. • Sliced bread and loafs • Sliced bread is whole, loafs are parts • Bread cannot exist without loafs • A loaf is part of only one sliced bread • What is it?
Examples, cont. • A classroom and equipment (chairs, projectors, desks) • The classroom is the whole, equipment is part • Remove the equipment, not a classroom anymore. • Each chair, desk can be part of only one classroom • Parts are of different kinds
Examples, cont. • Chair and parts • Chair cannot exist without parts • Each part can belong to exactly one chair • Parts are of different kinds
Composition vs. Aggregation • So confusing, that UML 2.0 drops the aggregation notation! Is this a good thing? • What to do? • Model composition if • Clearly, a whole/part association • Clearly, the component is part of only one composite at a time (i.e., composite sort of manages component) • If in doubt leave it as an association!
Sequence Diagrams • A class diagram shows a fixed (static) view of a system • A sequence diagram represents a dynamic view of a system by attempting to capture messages sends over time • Can document a scenario such as • User Selects Song
Sequence Diagrams • Objects are lined up on top in rectangles • Object names :theJukebox • Dashed lines represent lifetime of objects • Rectangles are activation lines • When the object has control • Activation bar of the receivers of the message is smaller than the sender's activation bar • Not much detail written
A Sequence diagram is a model that describes how groups of objects collaborate in some behavior over time and capturing the behavior of a single use case. It shows the objects and the messages that are passed between these objects in the use case.