ICT340 Seminar 4
ICT340 Seminar 4
ICT340
Application Analysis and Design
Implementations (Unit 5)
1
Official (Closed) - Non Sensitive
Implementations
2
Official (Closed) - Non Sensitive
Implementations
Recall the structural model
3
Official (Closed) - Non Sensitive
Implementations
class: Student
name: String
address: String
telephone: long
. . . // methods
4
Official (Closed) - Non Sensitive
public class Student
{ private String name;
Implementations private String address;
private int telephone;
. . .
6
Official (Closed) - Non Sensitive
Implementations
7
Official (Closed) - Non Sensitive
Implementations
After all the walkthroughs . . .
Admin
hasCustomers 1 1 hasBranches
* hasManagers
Employee
works in
* 1 *
1 1
BranchWorker Manager Branch
isResponsibleFor
1 has
* 0..*
signs toRent
Customer Contract Car
1 1 0, 1 1..* 8
Official (Closed) - Non Sensitive
Admin
hasCustomers 1 1 hasBranches
* hasManagers
Employee
works in
* 1 *
1 1
BranchWorker Manager Branch
isResponsibleFor
1 has
* 0..*
signs toRent
Customer Contract Car
1 1 0, 1 1..*
9
Official (Closed) - Non Sensitive
Consider 1
Implementations direction at a
time
Recall . . . toRent
Contract Car
0, 1 1..*
Implementations
toRent
Contract Car
0, 1 1..*
class: Car
regNo: String
contract: Contract
...
. . . // methods
Implementations – Java
toRent
Contract Car
0, 1 1..*
Implementations – Python
toRent
Contract Car
0, 1 1..*
... 13
Official (Closed) - Non Sensitive
Implementations
The other direction . . .
toRent
Contract Car
0, 1 1..*
Implementations
toRent
Contract Car
0, 1 1..*
class: Contract
duration: int
cars: HashMap
...
. . . // methods
Implementations – Java
toRent
Contract Car
0, 1 1..*
Recall collections
public class Contract
{ ...
class: Contract private HashMap cars; Why is a setter not
duration: int appropriate here?
...
cars: HashMap int getNumOfCar() { . . . }
... void addCar(Car aCar) { . . . }
boolean hasCar(Car aCar) { . . . }
. . . // methods Car searchCars(String regnNo) { . . . }
void listCar() { . . . }
boolean removeCar(String regnNo) { . . . }
...
}
16
Official (Closed) - Non Sensitive
Implementations – Python
toRent
Contract Car
0, 1 1..*
Recall collections
class Contract(object):
def __init__(self, nStartDate, nDuration):
self.__cars = {}
class: Contract ...
def getNumOfCar(self) :
duration: int ...
cars: HashMap def addCar(self, aCar):
... ...
def hasCar(self, aCar):
. . . // methods ...
def searchCars(self, regnNo):
...
def listCar(self) :
...
17
def removeCar(self, regnNo):
Official (Closed) - Non Sensitive
Implementations
18
Official (Closed) - Non Sensitive
:Admin branch1:Branch
5
assignManager(
location,
employeeName, branch1 =
employeeNumber) searchBranches(location) A sequence
diagram
4
aManager = new Manager
(employeeName, employeeNumber)
aManager:Manager
assignManager 3 setManager(aManager)
(aManager)
setBranch(branch1) 1
19
Official (Closed) - Non Sensitive
Admin
hasCustomers 1 1 hasBranches
* hasManagers
Employee
works in
* 1 *
1 1
BranchWorker Manager Branch
isResponsibleFor
1 has
* 0..*
signs toRent
Customer Contract Car
1 1 0, 1 1..*
20
Official (Closed) - Non Sensitive
class: SomeOtherClass
...
public void someMethod()
{ . . . aCircle: Circle
aCircle = new Circle(3);
ans = aCircle.findArea(); radius = 3
. . . ...
}
. . . // other methods
public double findArea()
{ . . .
}
. . .
22
Official (Closed) - Non Sensitive
:Admin branch1:Branch
5
assignManager(
location,
employeeName, branch1 =
employeeNumber) searchBranches(location) A sequence
diagram
4
aManager = new Manager
(employeeName, employeeNumber)
This is from the previous session. aManager:Manager
Did you recall how we drew this?
Remember why we have this arrow doing a “U-turn”
assignManager 3 setManager(aManager)
(aManager)
setBranch(branch1) 1
23
Official (Closed) - Non Sensitive
:Admin branch1:Branch
5 It is easier to start
from the bottom!
assignManager(
location,
employeeName, branch1 =
employeeNumber) searchBranches(location) What method is
used here?
4
aManager = new Manager
(employeeName, employeeNumber)
aManager:Manager
assignManager 3 setManager(aManager)
(aManager)
Who is receiving
2 the message?
Who is sending 1
setBranch(branch1)
the message? 24
Official (Closed) - Non Sensitive
Implementations
Admin
hasCustomers 1 1 hasBranches
* hasManagers
Employee
works in
How is it related
to this?
* 1 *
1 1
BranchWorker Manager Branch
isResponsibleFor
1 has
* 0..*
signs toRent
Customer Contract Car
1 1 0, 1 1..*
25
Official (Closed) - Non Sensitive
Implementations
Recall . . . isResponsibleFor
Manager Branch
1 1
assignManager 3 setManager(aManager)
(aManager)
2
Who is receiving
the message? setBranch(branch1) 1
27
Official (Closed) - Non Sensitive
Implementations
Admin
hasCustomers 1 1 hasBranches
* hasManagers
Employee
works in
How is it related
to this?
* 1 *
1 1
BranchWorker Manager Branch
isResponsibleFor
1 has
* 0..*
signs toRent
Customer Contract Car
1 1 0, 1 1..*
28
Official (Closed) - Non Sensitive
Implementations
Recall . . . isResponsibleFor
Manager Branch
1 1
In Java In Python
public class Branch class Branch(object):
{ ... class: Branch def __init__(self, nManager):
private Manager aManager; self.__aManager = nManager
...
aManager: Manager
...
public Manager getManager() ... def getManager(self):
{ return aManager; return self.a__Manager
}
public void setManager(Manager m) def setManager(self, m):
{ this.aManager = m;
. . . // methods self.__aManager = m
}
... ...
}
29
Official (Closed) - Non Sensitive
:Admin branch1:Branch
5
assignManager(
location,
employeeName, branch1 =
employeeNumber) searchBranches(location) What will the
assignManager()
4 method consist of?
assignManager 3 setManager(aManager)
(aManager)
Who is receiving
2
the message?
setBranch(branch1) 1
30
Official (Closed) - Non Sensitive
Implementations – Java
4
aManager = new Manager
(employeeName, employeeNumber)
aManager:Manager
assignManager 3 setManager(aManager)
(aManager)
setBranch(branch1) 1
32
Official (Closed) - Non Sensitive
:Admin branch1:Branch
5
Who is sending
assignManager( the message? What method
location, is used here?
employeeName, branch1 =
employeeNumber) searchBranches(location)
assignManager 3 setManager(aManager)
(aManager)
setBranch(branch1) 1
33
Official (Closed) - Non Sensitive
:Admin branch1:Branch
5
Who is receiving
assignManager( the message?
What will be done when this
location, message is received?
employeeName, branch1 =
employeeNumber) searchBranches(location)
What does this assignManager()
4 consist of ?
Who is sending aManager = new Manager
the message? (employeeName, employeeNumber)
aManager:Manager
assignManager 3 setManager(aManager)
(aManager)
setBranch(branch1) 1
34
Official (Closed) - Non Sensitive
branch1.assignManager(aManager);
}
Who is to receive the message for this method?
What does "this" refer to?
This is actually the method sent to the orchestrating object.
35
How does the whole thing work?
Official (Closed) - Non Sensitive
branch1 = self.searchBranches(location)
branch1.assignManager(aManager);
}
36
Official (Closed) - Non Sensitive
:Admin branch1:Branch
5 How the whole
Message thing work?
assignManager(
location,
employeeName, branch1 =
employeeNumber) searchBranches(location)
Responses to
A the message
4
aManager = new Manager
(employeeName, employeeNumber)
B aManager:Manager
C
assignManager 3 setManager(aManager)
(aManager)
public void assignManager(String location,
String employeeName,
2 String employeeNumber)
{
Branch branch1 = this.searchBranches(location);
setBranch(branch1)
A1
aManager = new Manager(employeeName, employeeNumber);
B 37
branch1.assignManager(aManager); C
Official (Closed) - Non Sensitive
Implementations
Gentle Reminders
This is a practical course
Reading and memorising will not work
Must do the exercises
Ask yourself
• “What is happening here?”
• “Why is this done?”
39
Official (Closed) - Non Sensitive
40