The specification is unchanged.
There is no analysis because the specification is unchanged.
The class CUSTOMER is split into two classes to separate the behaviour that belongs to a PERSON, and to a CUSTOMER. This allows other types of customer to be easily added in the future, such as corporations or customers with a joint account.
The attributes of a person are name, gender, and address. These are placed in a parent class PERSON, with the routines that set and use this data. The remaining attributes and routines are specific to a customer, so are placed in the child class CUSTOMER.
A CUSTOMER is a PERSON with a bank account, a unique identifier,
and a password. The routines associated with these three attributes live
in the class CUSTOMER. In the banking system, an object of type
PERSON is never created, only customers. Class PERSON has
thus been defined with an empty creation routine, so objects of this type
cannot be created.
The inheritance chart and class diagrams for CUSTOMER and PERSON are shown below.
The client chart is unchanged by
inheritance, so it is not shown here.
The existing CUSTOMER code is divided into the two classes PERSON
and CUSTOMER. The new code for this version is shown below; where
a routine is moved as a unit and is thus unchanged, only the routine header
is shown.
class PERSON
creation
feature {NONE}
name: STRING
get_name is
-- read in and set the name
gender: CHARACTER
get_gender is
-- loop until the user enters a valid gender code
read_gender is
-- read in a gender code
valid_gender: BOOLEAN
is
-- has a valid gender code been entered?
address: STRING
get_address is
-- read in and set the address
feature {ANY}
make is
-- set the personal details
do
io.putstring ("%NEnter the personal details%N")
get_name
get_gender
get_address
end -- make
show is
-- show the personal details
do
io.putstring ("%N ")
show_title
io.putstring (name)
io.putstring (" lives at ")
io.putstring (address)
end -- show
end -- class PERSON
class CUSTOMER
inherit
PERSON
rename
make as person_make,
show as person_show
end
creation {TELLER}
make
feature {NONE}
id: INTEGER
set_id (key: INTEGER)
is
-- set the id to key
do id := key end -- set_id
show_id is
-- show the customer identifier
do
io.putstring ("%NCustomer #")
io.putint (id)
io.putstring (": ")
end -- show_id
password: PASSWORD
account: ACCOUNT
menu: MENU
feature {TELLER}
make (id: INTEGER) is
-- set the customer details
do
io.putstring ("%NEnter the customer details%N")
person_make
!!account.make
!!password.make
!!menu.make (account)
end -- make
show is
-- show the customer details
do
person_show
io.putstring ("%NThe account details are:%N")
account.show
end -- show
feature {ATM}
match (id: INTEGER):
BOOLEAN is
-- does the customer key match this id?
end -- class CUSTOMER