Bài Giảng Phân tích thiết kế hướng đối tượng (phần 5)

Chia sẻ: Nguyen Kien | Ngày: | Loại File: PPT | Số trang:32

lượt xem

Bài Giảng Phân tích thiết kế hướng đối tượng (phần 5)

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tham khảo tài liệu 'bài giảng phân tích thiết kế hướng đối tượng (phần 5)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả

Chủ đề:

Nội dung Text: Bài Giảng Phân tích thiết kế hướng đối tượng (phần 5)

  1. Use case realization Lecture 5 Hoa Sen University 1
  2. Agenda  Notations  Dependency  Interaction and Class diagrams Hoa Sen University 2
  3. Interaction diagrams  Generalization of two more specialized UML diagram types – Sequence diagrams – Communication diagrams  Illustrate how objects collaborate via messages and methods Hoa Sen University 3
  4. Sequence vs. Communication diagram  Sequence diagrams :A myB : B illustrate interactions in a kind of fence format doOne doTwo – Easier to see the call doThree sequence – Large set of detailed notation options  Communication diagrams doOne :A illustrate interactions in a graph or network format 1: doTwo – More space-efficient 2: doThree myB : B Hoa Sen University 4
  5. Common notation: participants – lifeline box lifeline box representing the class lifeline box representing a Font, or more precisely, that Font is lifeline box representing an named instance an instance of class Class – an unnamed instance of class Sale instance of a metaclass «metaclass» :Sale s1 : Sale Font List is an interface lifeline box representing an lifeline box representing instance of an ArrayList class, one instance of class Sale, in UML 1.x we could not use an parameterized (templatized) to selected from the sales interface here, but in UML 2, this (or hold Sale objects ArrayList collection an abstract class) is legal sales: x : List sales[ i ] : Sale ArrayList related example Hoa Sen University 5
  6. Sequence diagram notation  Lifeline boxes : R egister : Sale and lifelines  Messages doX doA – Synchronous doB message a found m essage w hose sender w ill not – Found message be specified doC  Focus of control doD and execution execution specification specification bars bar indicates focus of control typical sychronous m essage show n w ith a filled-arrow line Hoa Sen University 6
  7. Sequence diagram notation  Illustrating reply or returns : Register : Sale – Using the message syntax returnVar = message(parameter). doX – Using a reply message line d1 = getDate  Message to “self” or “this” public class Register{ getDate public void doX(){ aDate … clear(); … : Register } doX public void clear(){ clear } } Hoa Sen University 7
  8. Sequence diagram notation note that newly created : Register : Sale objects are placed at their  Creation of instance creation "height" – In implementation: makePayment(cashTendered) create(cashTendered) : Payment invoke the new authorize operator and call the constructor  Object lifelines and object destruction : Sale create(cashTendered) – In language that : Payment the «destroy» stereotyped ... does not have message, with the large X and short lifeline «destroy» indicates explicit object garbage collection X destruction Hoa Sen University 8
  9. Sequence diagram notation  Diagram frames in UML sequence diagrams – Support conditional and looping construct :A :B makeNewSale a UML loop loop [ more items ] enterItem(itemID, quantity) frame, with a boolean guard expression description, total endSale Hoa Sen University 9
  10. Sequence diagram notation  Common frame operators Frame Meaning operator Alt Alternative fragment for mutual exclusion conditional logic expressed in the guards Loop Loop fragment while guard is true Opt Optional fragment that executes if guard is true Par Parallel fragments that execute in parallel Region Critical region within which only one thread can run Hoa Sen University 10
  11. Sequence diagram notation  Conditional messages public class foo{ : Foo : Bar Bar bar = new Bar(); xx … opt [ color = red ] public void m1(){ calculate bar.xx(); if (color.equals(“red”)) yy bar.calculate(); bar.yy(); : Foo : Bar xx } } [ color = red ] calculate  UML1.x style yy Hoa Sen University 11
  12.  Mutually exclusive conditional messages public class A{ :A :B :C B b = new B(); doX C c = new C(); public void doX(){ alt [ x < 10 ] … calculate if (x < 10) b.calculate(); [ else ] calculate else c.calculate(); } } Hoa Sen University 12
  13. Sequence diagram notation  Iteration over a collection lineItems[i] : : Sale This lifeline box represents one SalesLineItem instance from a collection of many t = getTotal SalesLineItem objects. lineItems[i] is the expression to loop select one element from the [ i < lineItems.size ] st = getSubtotal collection of many SalesLineItems; the ‘i” value refers to the same “i” in the guard i++ in the LOOP frame an action box may contain arbitrary language statements (in this case, incrementing ‘i’) it is placed over the lifeline to which it applies Hoa Sen University 13
  14. Sequence diagram notation public class Sale{ private List lineItems = new ArrayList(); public Money getTotal(){ Money total = new Money(); Money subtotal = null; for (SalesLineItem lineItem: lineItems){ subtotal = lineItem.getSubtotal(); total.add(subtotal); } lineItems[i] : } : Sale SalesLineItem } t = getTotal loop st = getSubtotal Hoa Sen University 14
  15. Sequence diagram notation  Nesting frames : Foo : Bar xx opt [ color = red ] loop(n) calculate Hoa Sen University 15
  16. Sequence diagram notation  Relate interaction diagrams  An interaction occurrence ( an interaction use) is a reference to an interaction within another interaction.  Two related frames – A frame around an entire sequence diagram, labelled with the tag sd and a name, – A frame tagged ref, called a reference, that refers to another named sequence diagram; Hoa Sen University 16
  17. Sequence diagram notation sd AuthenticateUser :B :C :A :B :C authenticate(id) doX doA doM1 doB doM2 authenticate(id) ref AuthenticateUser ref sd DoFoo DoFoo :B :C interaction occurrence doX note it covers a set of lifelines doY note that the sd frame it relates to doZ has the same lifelines: B and C Hoa Sen University 17
  18. Sequence diagram notation  Messages to classes to invoke static methods public class Foo{ public void doX(){ Locale[] locales = Calendar.getAvailableLocales(); .. } } message to class, or a static method call doX 1: locs = getAvailableLocales «metaclass» : Foo Calendar Hoa Sen University 18
  19. Sequence diagram notation Payment {abstract} Payment is an abstract authorize() {abstract} superclass, with concrete ... subclasses that implement the polymorphic authorize operation Polymorphic messages and cases CreditPayment authorize() DebitPayment authorize() ... ... object in role of abstract polymorphic message superclass :Register :Payment {abstract} doX authorize stop at this point – don’t show any further details for this message :DebitPayment :Foo :CreditPayment :Bar authorize authorize doA doX doB separate diagrams for each polymorphic concrete case Hoa Sen University 19
  20. Sequence diagram notation  Asynchronous and synchronous calls – Call does not wait for a response – Asynchronous calls are used in multi-thread application – Show as a stick arrow message – It is common for modeler to use stick arrow to represent synchronous message – Do not assume the shape of the arrow is correct Hoa Sen University 20



Đồng bộ tài khoản