Download presentation
Presentation is loading. Please wait.
Published byEarl Pitts Modified over 9 years ago
1
Software Engineering Modern Approaches Eric Braude and Michael Bernstein 1
2
© 2010 John Wiley & Sons Ltd. Chapter 16: Unified Modeling Language 2
3
Learning Goals of This Chapter What is the UML notation for classes and packages of classes? How does UML represent class relationships such as inheritance, aggregation, and dependency? What is a sequence diagram? How are UML activity diagrams related to flow charts? Requirements analysis Design Implementation Testing Maintenance Planning The Software Development Lifecycle Phase most relevant to this chapter is shown in bold © 2010 John Wiley & Sons Ltd. 3
4
Classes at Detailed Design + numCanisters: int - numWafers: int - size: float Canister Class name Attribute: type wafer canister © 2010 John Wiley & Sons Ltd. 4
5
Classes at Detailed Design Responsibilities: -- describes each canister undergoing fabrication + display() - getNumOpenSlots() + setStatus() + numCanisters: int - numWafers: int - size: float Canister Class name Attribute: type Operations Place for comments +:Visible from without wafer canister © 2010 John Wiley & Sons Ltd. 5
6
package of classes package myPackage; class MyFirstClass { … } UML Notation … and … Typical Implementation package myPackage.mySubPackage; class MyClass { … } mySubPackage myPackage © 2010 John Wiley & Sons Ltd. 6
7
public package myPackage; class MySecondClass { … } package of classes package myPackage; class MyFirstClass { … } UML Notation … and … Typical Implementation MyFirstClass «hidden» «visible» acccessibility of classes from outside package package myPackage.mySubPackage; class MyClass { … } mySubPackage MyClass MySecondClass myPackage sub-package © 2010 John Wiley & Sons Ltd. 7
8
class Employer { Employee[ ] employees;..... } class Employee { Employer[ ] employers;..... } EmployerEmployee Association : UML Notation employs is employed by © 2010 John Wiley & Sons Ltd. 8
9
EmployerEmployee Multiplicity : UML Notation 1..* 1..3 employs is employed by Personalnfo 1 © 2010 John Wiley & Sons Ltd. 9
10
abstract class package MyPackage; abstract class MyAbstractClass......... UML Notation … and … Typical Implementation MyPackage MyAbstractClass © 2010 John Wiley & Sons Ltd. 10
11
abstract class package MyPackage; abstract class MyAbstractClass.... package MyPackage; class MyDerivedClass extends MyAbstractClass { int att;..... void myFunction( ReferencedClass r ) {... } } MyDerivedClass att: int myFunction() UML Inheritance … and … Typical Implementation MyPackage attribute operation inheritance MyAbstractClass © 2010 John Wiley & Sons Ltd. 11
12
interface interface MyAbstractClass.... class MyClass implements MyInterface {..... } MyClass myMethod() Interfaces UML Notation …… Typical Java Implementation realization MyInterface myMethod() © 2010 John Wiley & Sons Ltd. 12
13
class Company { Employee emp; int att;..... } Company att: int myFunction() Employee emp aggregation Aggregation : UML Notation and Typical Implementation * EmployeeDirectory att: int myFunction() emp * class EmployeeDirectory { Employee emp; int att;..... } aggregation © 2010 John Wiley & Sons Ltd. 13
14
class Company { class Employee emp; {... }..... } Company att: int myFunction() Employee emp composition Composition: UML Notation and Typical Implementation * EmployeeDirectory att: int myFunction() emp * class EmployeeDirectory { class Employee emp; {... }..... } composition © 2010 John Wiley & Sons Ltd. 14
15
class MyClass {..... void myFunction1( MyReferencedClass r ) {... }.... } MyClass att: int myFunction() MyReferencedClass Dependence : UML Notation … and …Typical Implementation dependence (reference to a class) parameter © 2010 John Wiley & Sons Ltd. 15
16
class MyDependentClass {..... void myFunction1( MyReferencedClass r ) {... } MyReferencedClass myFunction2( … ) {... } void myFunction3( … ) { MyReferencedClass m … } MyDependentClass att: int myFunction() MyReferencedClass Dependence : UML Notation … and …Typical Implementation dependence (reference to a class) parameter or return type or local variable type © 2010 John Wiley & Sons Ltd. 16
17
Customer Mail Application generateMail() getCustomerTypeFromUser() main() Customer createMail() customer1 © 2010 John Wiley & Sons Ltd. 17
18
Customer Mail Application generateMail() getCustomerTypeFromUser() main() Customer createMail() DelinquentCustomer createMail() MountainCustomer createMail() RegularCustomer createMail() customer1 © 2010 John Wiley & Sons Ltd. 18
19
EmployerEmployee Example of an Object Model 1..n 1..3 joe:Employee ajaxCorp:Employer sue:Employee abcCorp:Employer Class Model One Particular Derived Object Model © 2010 John Wiley & Sons Ltd. 19
20
© 2010 John Wiley & Sons Ltd. 1. read() Sequence Diagram for Check Out Use Case User :BarCodeReader doCheckout() :MainScreen Use case: 1. User swipes bar code 2. Application prompts for rental duration 3. User enters duration 4. Application stores record 5. Application prints customer’s account status 20
21
© 2010 John Wiley & Sons Ltd. Beginning of Sequence Diagram for Check Out Use Case Clerk :BarCodeReader :Checkout initiate() show() :CheckoutOptionDisplay } Step 1 of use case order doCheckout() :MainScreen read() { Step 2 of use case Originates from use case: 1. User swipes bar code 2. Application prompts for rental duration 3. User enters duration … 21
22
© 2010 John Wiley & Sons Ltd. 4. store() 2.3 show() 3. setDuration() 1. read() Sequence Diagram for Check Out Use Case User :BarCodeReader doCheckout() :MainScreen This sequence diagram originates from Use case: 1. User swipes bar code 2. Application prompts for rental duration 3. User enters duration 4. Application stores record 5. Application prints customer’s account status :Checkout 2.1 initiate() :CheckoutOptionDisplay :Account 2.2 create() 5. print() 22
23
EncounterGa me Sequence Diagram Showing Concurrency freddie: ForeignCharacter move mainPlayer- Character: PlayerCharacter create & display move create & display Player © 2010 John Wiley & Sons Ltd. 23
24
© 2010 John Wiley & Sons Ltd. 1. Identify the use case whose sequence diagram you will build (if applicable). 2. Identify which entity initiates the use case – the user, or – an object of a class name the class name the object if possible 3. If not the user, draw a rectangle to represent this initiating object at left top – use UML object:Class notation 4. Draw an elongated rectangle beneath this to represent the execution of the operation initiating the process 5. Draw an arrow pointing right from it Building a Sequence Diagram 1 myObject :MyClass 24
25
© 2010 John Wiley & Sons Ltd. Building a Sequence Diagram 2 6. Identify which entity handles the operation initiated – an object of a class name the class name the object 7. Label the arrow with the name of the operation 8. Show a process beginning, using an elongated rectangle 9…… Continue with each new statement of the use case. myObject :MyClass myObject1 :MyClass1 operation() 25
26
CheckingOut State/Transition Diagram for OnlineShopper Class Browsing ItemsChosen select item © 2010 John Wiley & Sons Ltd. 26
27
Hit checkout button CheckingOut State/Transition Diagram for OnlineShopper Class Browsing ItemsChosen CreditUnderValidation CreditDenied Complete Incomplete hit Submit button [credit card data incomplete] [credit card data complete] put back last item select item hit OK validation received denial received hit OK hit Quit select item © 2010 John Wiley & Sons Ltd. 27
28
Conditions on Events CreditUnderValidation Incomplete Hit Submit button [credit card data incomplete] [credit card data complete] © 2010 John Wiley & Sons Ltd. 28
29
Activity Diagram Example protected final void setName( String aName ) { // Check legitimacy of parameter and settings if( ( aName == null ) || ( maxNumCharsInName() <= 0 ) || ( maxNumCharsInName() > alltimeLimitOfNameLength() ) ).... Parameter & settings make sense else © 2010 John Wiley & Sons Ltd. 29
30
Activity Diagram Example protected final void setName( String aName ) { // Check legitimacy of parameter and settings if( ( aName == null ) || ( maxNumCharsInName() <= 0 ) || ( maxNumCharsInName() > alltimeLimitOfNameLength() ) ) { name = new String( "defaultName" ); System.out.println ( "defaultName selected by GameCharacter.setName()"); } else // Truncate if aName too long if( aName.length() > maxNumCharsInName() ) name = new String ( aName.getBytes(), 0, maxNumCharsInName() ); else // assign the parameter name name = new String( aName ); } Nominal path Set name to “defaultName" Truncate name Set name to parameter Parameter & settings make sense else Parameter name too long else Output notification to console © 2010 John Wiley & Sons Ltd. 30
31
Activity Chart Notation Do Something Do Something More Do A TaskDo Another Task Do Even More else[condition true] } In parallel © 2010 John Wiley & Sons Ltd. 31
32
Activity Diagram for soughtFact.proveBack() Apply R.proveAntecedents()* Report TRUE Report FALSE else Another rule R exists with soughtFact as its consequent else soughtFact in factList FactRule * Prove that every antecedent fact is true proof succeeded © 2010 John Wiley & Sons Ltd. 32
33
A Class Model for Chaining Rule addRule() proveAntecedents() forwardChain() Fact content addFact() proveBack() consequent antecedents 1 1..n © 2010 John Wiley & Sons Ltd. 33
34
A Class Model for Chaining Rule addRule() proveAntecedents() forwardChain() Fact content addFact() proveBack() consequent antecedents static factList static ruleBase 1 1..n © 2010 John Wiley & Sons Ltd. 34
35
A Class Model for Chaining Rule addRule() proveAntecedents() forwardChain() Fact content addFact() proveBack() consequent antecedents static factList static ruleBase Set Fact.factList to the known facts and a Rule.ruleBase to the known rules. Create Fact object soughtFact Execute soughtFact.proveBack( ruleBase ); 1 1..n © 2010 John Wiley & Sons Ltd. 35
36
© 2010 John Wiley & Sons Ltd. Data Flow Models in UML Process part order This example is adapted from RJB UML Reference Part order Price list Ship part order Charge Credit card Credit card data Parts list «datastore» Charge amount 36
37
© 2010 John Wiley & Sons Ltd. Specifications for Figure Drawing Facilitate drawing stick figures Drag to vicinity to auto-complete Feet can be rectangles or ellipses (Rest to be specified) Releasing dragged figure anywhere in this area causes it to appear in position at end of left leg 37
38
Bad Attempt: “A Foot is Either an Ellipse or a Rectangle” Foot EllipseRectangle © 2010 John Wiley & Sons Ltd. 38
39
Better Attempt: “A Foot is Either an Ellipse or a Rectangle” RectangleFoot FootRectangleEllipse EllipseFoot © 2010 John Wiley & Sons Ltd. 39
40
Another Attempt: “A Foot is Either an Ellipse or a Rectangle” FootFootShape EllipseRectangle © 2010 John Wiley & Sons Ltd. 40
41
Best Attempt So Far: “A Foot is Either an Ellipse or a Rectangle” Foot draw() FootShape drawAsEllipse() drawAsRectangle() Ellipse draw() Rectangle draw() © 2010 John Wiley & Sons Ltd. 41
42
© 2010 John Wiley & Sons Ltd. 42
43
© 2010 John Wiley & Sons Ltd. Sequence Diagram for Figure Drawing Application :FootShape:Foot releaseCursor drawAsEllipse* :Ellipse draw( aPosition ) :Area draw ( GeometricFigure aGeometricFigure ) ( Position aPosition ) ( Leg aLeg, GeometricFigure aGeometricFigure ) * or drawAsRectangle() … 43
44
© 2010 John Wiley & Sons Ltd. Relationships Between Classes Package group of related classes Inheritance take on attributes and operations from other classes “is-a” relationship e.g. an Employee “is-a” Person Association structural relationship between classes Aggregation structural inclusion of object on one class by another “whole-part” relationship …… 44
45
© 2010 John Wiley & Sons Ltd. Relationships Between Classes Package Inheritance Association Aggregation structural inclusion of object on one class by another “whole-part” relationship Composition Stronger form of aggregation Included object is created and destroyed when including object is created and destroyed Dependency one class depends on another changes to depended on class affects dependent class 45
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.