draw a sequence diagram

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

Ch 12: Object-Oriented Analysis
Visual Basic: An Object Oriented Approach 6: Object Modelling.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
Object Oriented Software Development
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 1 Introduction to Object-Oriented Programming and.
Introduction to Sequence Diagrams
Information Session for Accommodation & Hospitality Staff: Electronic Leave Recording using iTrent.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Lists. Container Classes Many applications in Computer Science require the storage of information for collections of entities e.g. a student registration.
Objective You will be able to define and identify the basic components of a java program by taking notes, seeing examples, and completing a lab. Construction.
Unit 1 INTRODUCTION TO MODELING AND CLASS MODEL Ref : L7-UML.PDF.
1 Object-Oriented Programming Using C++ CLASS 5. 2 Object Composition Object composition occurs when a class contains an instance of another class. Creates.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL.Net Assignments K. R. C. Wijesinghe Trainer Virtusa Corporation.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Object Oriented Software Development
Sequence Diagrams And Collaboration Diagrams HungNM.
Introduction to Java Java Translation Program Structure
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
22/11/ Selection If selection construct.
Chapter 4 Introduction to Classes, Objects, Methods and strings
QUEUES What are Queues? Creating a Queue Enqueuing and Dequeuing Testing for an Empty Queue.
CSC 212 – Data Structures Lecture 5: Variables. Problem of the Day Why do underground subway stations always have more escalators going up than down?
31/01/ Selection If selection construct.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
1 4.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works. Directly testing if text boxes.
CSE 1020:Using Objects Mark Shtern 1-1. Summary Read API Method binding and overloading Development process Input validation Assert 1-2.
1 M206 Chapter 31: An Overview of Software Development 1.Defining the problem 2.Analyzing the requirement – constructing initial structural model 3.Analyzing.
CHAPTER
Object-Orientated Analysis, Design and Programming
CSC111 Quick Revision.
Linked Lists in Action Chapter 5 introduces the often-used data public classure of linked lists. This presentation shows how to implement the most common.
Objectives State the reasons for the complexity involved in the development of software Define the following terms Objects Classes Messages Methods Explain.
Introduction to Unified Modeling Language (UML)
CHAPTER 4 Test Design Techniques
Programming – Touch Sensors
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
OO Domain Modeling With UML Class Diagrams and CRC Cards
ALGORITHMS AND FLOWCHARTS
Arrays, For loop While loop Do while loop
The Basics of Class Diagrams for a single class
Separate Compilation and Namespaces
Defining Your Own Classes Part 1
Entity relationship diagrams
Writing Methods AP Computer Science A.
Chapter 11 Following the Trail; Examining Execution Sequences
ALGORITHMS AND FLOWCHARTS
If selection construct
Do While (condition is true) … Loop
4.1 Strings ASCII & Processing Strings with the Functions
Interaction diagrams Interaction diagrams are models that describe how groups of objects collaborate in some behavior. Typically, an interaction diagram.
If selection construct
Defining Classes and Methods
3.1 Iteration Loops For … To … Next 18/01/2019.
Flowcharts and Pseudo Code
CSC 143 Java Errors and Exceptions.
Object Oriented System Design Class Diagrams
Chapter 9 Introduction To Classes
Software Design Lecture : 39.
Classes and Methods 15-Aug-19.
Presentation transcript:

draw a sequence diagram uses case “remove a member from the library” “remove a customer from the bank” draw a sequence diagram Mark 50 - 59 %

Mark 50 - 59 % Write a series of statements for the use case scenario "remove a member from the library". Include variants for both a member with and without some current loans. Then draw two Sequence Diagrams to trace all messages starting from 'aLibrary.removeMember("aName")'. 1.Run the LibraryCW3.java program code (page 16). At the viva you will be asked to explain the code and outcomes and compare with your answers to (1) above. When answering use terms such as 'pre-condition', 'visibility', 'association', 'delegation', 'responsibility' etc.

How do you draw a sequence diagram ? Five steps (suggestions) statements describe as activities - concentrate on ‘what’ has to happen not ‘how’ pre-conditions what activities are constraints - these activities must happen before others sequence arrange activities in a sequence - logically, without reference to a class diagram class responsibilities add operations and attributes to a class diagram, note :- navigation, multiplicity, visibility, etc sequence diagram draw your diagram -

“remove a customer from the bank” statements describe as activities - concentrate on ‘what’ has to happen not ‘how’ “remove a customer from the bank” given a customer identifier aName “Mohammed” get the customer remove the customer remove all of the accounts of the customer

need to confirm all four before removal of a customer pre-conditions what activities are constraints - these activities must happen before others a customer must be a customer of the bank before they can be removed a customer cannot be removed if they have an account (s) an account cannot be removed if it is ‘open’ an account can only be closed if its balance is zero need to confirm all four before removal of a customer

sequence arrange activities in a sequence - logically, without reference to a class diagram enter a customer identifier “Mohammed” get the object that represents the customer “Mohammed” check if all of the customers accounts are closed close all the accounts of the customer remove the customer object remove the customer’s account objects note the last two activities do not need to be completed in this sequence

class responsibilities class responsibilities add operations and attributes to a class diagram, note :- navigation, multiplicity, visibility, etc examine the existing draft class diagram - what is the behaviour / responsibilities of these classes ?

Bank BankCustomerBase AccountBase Person BankAccount Current Savings BankCustomer

Bank aCustomerBase anAccountBase BankCustomerBase customers AccountBase accounts Person BankAccount owner balance open Current Savings 1 0 ..3 BankCustomer accounts[]

1. it is the responsibility of the bank application to deal with data input and output enter the name of the bank customer to be removed the bank delegates the responsibility of getting a customer of the bank, to its collection of customers, aCustomerBase, the bank sends a message to aCustomerBase to get a customer with this name

2. aCustomerBase, as an instance of BankCustomerBase has a collection of customer objects, it is responsible for knowing if it has any objects in its collection, but it is not responsible for knowing about the details; state or behaviour of these objects, a collection can self delegate messages to itself such as size() isEmpty() the bank checks if it includes a customer with this name aCustomerBase collaborates with each customer object to check if it includes a customer with this name, aCustomerBase repeatedly sends a message to each object in its collection, each customer object is asked for its name, all customer objects are responsible for knowing their names, aCustomerBase is responsible for checking whether the name of a customer (s) is the same as the name of the customer to be removed if after searching through the customers a customer exists with this name then the customer object is returned to the bank,

3. the bank delegates to the customer, the responsibility of checking whether all the accounts of the customer are (or can be) closed, the customer has a collection of all the accounts it owns (see the class diagram) check if all of the customers accounts are closed the customer can delegate the responsibility of checking whether all of its accounts are or can be closed to each account, an account is responsible for knowing whether it is open or closed note :- a bank has anAccountBase, an aggregation of accounts, the bank could delegate to this collection, the responsibility of checking whether all the accounts of the customer are ‘closed’ - but then this would mean an enquiry is sent to all accounts in the bank !

an account is owned by exactly one customer ” 4. once all pre-conditions have been met the bank can remove a customer object and all its accounts, remove the customer object from the bank, the bank delegates the responsibility of removing a customer object to the bases it is composed of, note :- if there is a two way ‘link’ between a customer and its accounts then the customer object needs to be removed from the customerBase and all associated account objects need to be removed from the accountBase remember “ a customer can own zero to three accounts, an account is owned by exactly one customer ”

the bank delegates the responsibility of removing a customer object to the bases it is composed of, a message can be sent to the customerBase to remove the customer a message can be sent to the accountBase to remove all of the accounts of the given customer note :- the sequence order of the above two activities is not important, 5. aCustomerBase can remove a customer object from its collection of customers, the pre-condition is that all the accounts of the customer can or are closed, remove the customer object from the bank,

close all the accounts of the customer 6. A customer is responsible for knowing about all of its accounts, an account knows whether it is open or closed, an account can only be closed if its balance is zero, an account knows its balance, (see class diagram) close all the accounts of the customer a customer can request all of its accounts to close themselves … a customer can then be responsible for removing all of its accounts from its collection of accounts note :- a customer does not need to remove all of its accounts from its own collection of accounts - since we are going to remove all of these account objects from the accountBase - hence the bank !

remove the customer’s account objects, the bank delegates the responsibility of removing the accounts of a customer object to the bases it is composed of, a message can be sent to the accountBase to remove all of the accounts of the given customer 7. anAccountBase can remove account objects from its collection of accounts, the pre-condition is that all the accounts of the customer can or are closed, remove the customer’s account objects, the pre-condition that all of these accounts can or have been closed has already been met,

For a Mark 50 - 59 % we need to draw two diagrams showing different ways to remove a member / customer … a large diagram can be shown as many related diagrams - the sequence for large parts of a use case can often vary this depends upon associations, navigation etc e.g. do we use the collection of accounts in a customer or do we search through all the accountBase for a customers accounts ? different ways - you cannot just ‘reverse engineer’ a solution from the code !

: Bank : BankCustomerBase : BankCustomer use case ”remove a customer” removeCustomer(“Mohammed”) use case ”remove a customer” a pre-condition is that the customer is a customer of the bank the bank delegates the responsibility of getting the object that represents “a customer” to its customerBase the customerBase collaborates with each customer - to get the customer “Mohammed” getCustomer(“Mohammed”) * getName( ) aCustomer [ getName == “Mohammed” ] A customer object or null is returned to the bank the use case / sequence diagram continues on a separate diagram

use case ”remove a customer” : BankCustomerBase : BankCustomer : BankAccount canRemoveCustomer(aCustomer) use case ”remove a customer” a pre-condition is that all the accounts of the customer can or are closed the bank delegates the responsibility of checking whether the customer can be removed to its customerBase the customerBase delegates to the customer the responsibility of knowing if it can close all of its accounts canCloseAllAccounts( ) * canBeClosed( ) “true” “true” the customer collaborates with each account - accounts are responsible for knowing if they can be closed, they know their balance and have an ‘open’ attribute

use case ”remove a customer” : BankCustomerBase : BankCustomer : BankAccount removeCustomer(aCustomer) use case ”remove a customer” the pre-condition that all the accounts of the customer can or are closed - has been tested the customer can remove its accounts (from its collection) the customer delegates the closing of accounts - to the accounts the customer is responsible for removing its accounts from its own collection removeAllAccounts( ) * close( ) “true” removeAccounts( ) remove(aCustomer ) the customerBase is responsible for removing the customer object from its collection of customers

use case ”remove a customer” : AccountBase : BankAccount : BankCustomer removeAllAccountsOf(aCustomer) use case ”remove a customer” the pre-condition that all the accounts of the customer can or are closed - has been tested the accountBase can remove all the accounts (from its collection) accounts ‘know’ their owner / customer the accountBase confirms the accounts are closed each account is removed from the accountBase collection of accounts getAllAccountsOf(aCustomer ) * getOwner( ) [ getOwner == aCustomer ] * isClosed( ) * removeAccount( aNumber)

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 75 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 255.5 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 75 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 255.5 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 75 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 255.5 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 0 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 0 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 0 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 0 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 0 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 0 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 0 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 0 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 75 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 255.5 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

… Remove the comments below and run the code, fully explain the code, outcomes and compare with your answers shown in your sequence diagrams. When answering try to use terms such as 'pre-condition', 'visibility', 'association','delegation', 'responsibility', ... etc. */ // show that account 1003 is owned by "Mohammed" System.out.println("\n\"aBank.getAccountNumber(1003)\"\n"); System.out.println(aBank.getAccountNumber(1003)); ...

<< BankCustomerBase >> /** Removes the specified customer. * Pre-condition: the customer must exist in the list of customers of the bank customer base, * all of the accounts of the customer are closed - so the customer can be removed.*/ public void remove(BankCustomer aCustomer) { customers.remove(aCustomer); } This method was made public here to demonstrate teaching points about ‘pre-conditions’, ‘associations’ and ‘encapsulation’ but this method should be private. It is not designed to be responsible for making the check that the customer has no accounts - it simply removes a customer without checking. << BankCustomerBase >> /** Removes the specified customer. * Pre-condition: the customer must exist in the list of customers of the bank customer base, * all of the accounts of the customer are closed - so the customer can be removed.*/ private void remove(BankCustomer aCustomer) { customers.remove(aCustomer); }

<< Bank >> /** Returns a string to confirm the removal of a customer with a given name. The bank * is responsible for getting a customer with a given name. If the customer is in the * bank then the customer base of the bank is responsible for checking whether the bank * can remove a customer. A customer base is responsible for removing a customer, the * account base of the bank is responsible for removing all the accounts of a customer. */ public String removeCustomerNamed(String aName) { String confirmation = new String(); confirmation = "\nAttempting to remove a customer and accounts \n"; BankCustomer aCustomer = this.getCustomerNamed(aName); if(aCustomer != null) if(aCustomerBase.canRemove(aCustomer) ) {confirmation += aCustomerBase.removeCustomer(aCustomer) ; confirmation += anAccountBase.removeAllAccountsOf(aCustomer) ; return confirmation; } else return confirmation += aCustomerBase.removeCustomer(aCustomer); return confirmation += "No customer named " + aName + " found - cannot remove \n";

<< BankCustomerBase >> /** Returns a string indicating the removal of an object representing a customer. * A customer is responsible for removing all of its accounts. If a customer can * remove all of its accounts then the bank customer base is responsible for and * will remove the object representing a customer. * Pre-condition : that the given customer object, representing a customer is * included in the list of customers of the bank customer base. */ public String removeCustomer(BankCustomer aCustomer) { if( aCustomer.removeAllAccounts() ) this.remove(aCustomer); return "Removed " + aCustomer.getName() + "\n"; } return aCustomer.getName() + " has open accounts and cannot be removed";

<< BankCustomerBase >> /** Removes the specified customer. * Pre-condition: the customer must exist in the list of customers of the bank customer base, * all of the accounts of the customer are closed - so the customer can be removed.*/ public void remove(BankCustomer aCustomer) { customers.remove(aCustomer); } This method was made public here to demonstrate teaching points about ‘pre-conditions’, ‘associations’ and ‘encapsulation’ but this method should be private. It is not designed to be responsible for making the check that the customer has no accounts - it simply removes a customer without checking. << BankCustomerBase >> /** Removes the specified customer. * Pre-condition: the customer must exist in the list of customers of the bank customer base, * all of the accounts of the customer are closed - so the customer can be removed.*/ private void remove(BankCustomer aCustomer) { customers.remove(aCustomer); }

aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aBank : Bank aCustomerBase= BankCustomerBase anAccountBase = AccountsBase aCustomerBase : BankCustomerBase [ customer1, customer2, customer3, …] anAccountBase : AccountBase [ savings1, current1, account1] customer1 : BankAccountCustomer name = ”Mohammed" age = 56 gender = 'M' accounts = [current1, savings1] savings1 : Savings number = 1003 balance = 75 interestRate = 5 owner = customer1 current1 : Current number = 1002 balance = 255.5 overdraft = 500 owner = customer1 customer3 : BankAccountCustomer name = ”Bob" age = 39 gender = 'M' accounts = [account1] account1 : BankAccount number = 1001 balance = 0 open = false owner = customer3 customer2 : BankAccountCustomer name = ”Mary" age = 21 gender = 'F' accounts = [ ]

encapsulation "Wrapping data and operations within an object. The data stored may only be manipulated by the operations provided." visibility "Operations and attributes of a class declared as public can be accessed by all other classes, operations and attributes declared as private can be accessed only by the class itself. To make any private attributes visible public operations must be provided "