Software design - Lecture 25. The main topics covered in this chapter include: object creation; object creation order entry example; object destruction; object destruction order entry example; guards in sequence diagram; conditional message sequence diagram;...
1 Software Design Lecture : 25 Object Creation • An object may create another object via a message Preferred :A :B Constructor :A :B Object Creation: Order Entry Example Order * OrderLine * CatalogEntry quantity: integer cost: float : Order : Client add(qty,part) Object creation : CatalogEntry : OrderLine getCost() return cost Object Destruction An object may destroy another object via a message An object may destroy itself Avoid modeling object destruction unless management is critical :A :B memory Object Destruction: Order Entry Example : Order : Client remove(line) : OrderLine X Object deletion Guards in Sequence Diagram When modeling object interactions, there will be times when a condition must be met for a message to be sent to the object. Guards behaves likes if statements in the sequence diagram They are used to control the flow We place the guard (bars) element above the message line being guarded and in front of the message name Student Registration in a class Another Example of Guards Conditional Message: Sequence Diagram : Client : Order add(qty,part) : CatalogEntry getStockLevel(part) return s : OrderLine [s>=qty] OrderLine(qty,part) getCost() return cost 11 Combined Fragment Combined fragment is an interaction fragment which defines a combination (expression) of interaction fragments A combined fragment is defined by an interaction operator and corresponding interaction operands For every option there will be corresponding action 12 ALT (UML 2.0) in Sequence Diagram Alt keyword represents alternatives to designate a mutually exclusive choice between two or more message sequences Alternatives are used to simulate “if then else” situation as it occur in the programming languages Guards are used to simulate Alternatives in Sequence diagram 13 Scenario i The user will submit the cheque for withdraw ii Bank will check the amount of cheque to be withdrawn iii Bank will check the amount available in the account iv If balance >amount to be withdrawn then debit transaction is performed and photo of cheque is stored v Otherwise the cheque will be returned with message of insufficient fund 14 15 Option Combination Fragment • The option combination fragment is used to model a sequence that, given a certain condition, will occur; otherwise, the sequence does not occur • An option is used to model a simple "if then" statement without “else” 16 17 Recurrence (Loop) in Sequence Diagram At time repetitions is required to control the flow of the programs Recurrence are like loops in the programming language Different Versions of UML represents Recurrence differently, we are using UML 2 18 19