Download presentation
Presentation is loading. Please wait.
1
draw a sequence diagram
uses case “remove a member from the library” “remove a customer from the bank” draw a sequence diagram Mark %
2
Mark % 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.
3
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 -
4
“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
5
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
6
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
7
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 ?
8
Bank BankCustomerBase AccountBase Person BankAccount Current Savings BankCustomer
9
Bank aCustomerBase anAccountBase BankCustomerBase customers AccountBase accounts Person BankAccount owner balance open Current Savings BankCustomer accounts[]
10
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
11
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,
12
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 !
13
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 ”
14
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,
15
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 !
16
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,
17
For a Mark % 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 !
18
: 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
19
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
20
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
21
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)
22
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 = [ ]
23
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 = [ ]
24
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 = [ ]
25
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 = [ ]
26
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 = [ ]
27
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 = [ ]
28
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 = [ ]
29
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 = [ ]
30
… 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)); ...
31
<< 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); }
32
<< 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";
33
<< 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";
34
<< 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); }
36
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 = [ ]
37
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 "
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.