Sei sulla pagina 1di 14

Library System

1
Library System

Tasks
Create an object model by following these steps:

1. Use the problem domain description to identify candidate classes (concepts) by
looking for nouns and noun phrases.

2. Identify attributes and assign them to the appropriate classes. Any class for which you
cannot find any attributes may not be a true domain class.

3. Look for opportunities of generalization or specialization by adding inheritance where
appropriate. Make sure you apply the "is-a" sentence rule.

4. Identify any composition or associations between classes by investigating all noun
phrases. Make sure to give all associations meaningful names and proper
multiplicities.


Library System
2
Problem Domain Description

The library for which we design this system has only books and magazines that are
available for library members to borrow.

Most books may be borrowed for 21 days, but some books only for 7 days. Most
magazines may be borrowed for 7 days, but some only for 3 or 5 days.

All members of the library get assigned a unique member number. We also store the first
and last names, address (street, city, state, zip) and phone number of every member.

Books have a title, ISBN number, list of authors and availability. Magazines have a title
and issue number. Authors have a first and last names, address (street, city, state, zip),
phone number, credentials and a short bio.

The library has multiple copies for some popular books and magazines. Every copy of a
book or magazine has its own unique copy number.

We also store the history of all the loans a library member made in the past, with the
checkout date and return date for every book that the library member checked out.

Members can also reserve books and magazines, and our system needs to keep track of
which member reserves what book or magazine at what date.

When a copy is returned it gets assigned to the oldest outstanding reservation, if any. The
copy is then put on hold. The date when the reservation status changes to "on hold" is
recorded. If the member does not pick up the copy within 7 days the reservation status
changes to "cancelled" and the copy is put back on the shelf.



Library System
3
Candidate Classes (Concepts)

Book
Magazine
Member
Copy
LoanHistory
Reservation
History
Author
Address
Library


Library System
4
Adding Attributes
Book
ISBN
authors
title
maxCheckoutLength
Magazine
issueNo
title
maxCheckoutLength
Member
memberNo
firstName
lastName
phone
Copy
copyNo
Loan
checkoutDate
returnDate
Reservation
statusDate
status
LoanHistory
Author
firstName
lastName
phone
credentials
shortBio
Address
street
city
state
zip
Library

Library System
5
Observations and Considerations regarding Attributes

Library has no attributes:
o Hence may not be a real concept.
o The library is the system we are modeling, hence does not need to appear
on the object model.
o Remove it.

LoanHistory has no attributes:
o Hence may not be a real concept.
o However, we cannot be sure until we consider relationships.
o Keep it for now.

Reservation has a reservation date and a "on hold" date and possibly a
cancellation date:
o We could make these all separate date attributes if we want to remember
the dates for each status change.
o However, here it was decided that it is sufficient to remember the last
status change date only.

maxCheckoutLength
o Is the same for all books or magazines.
o Hence, should probably be stored as constants.
o Which makes it more a design or implementation detail.
o Hence, omit for now.

Address
o Could be simply attributes in both Member and Author classes
o However, since it is possible that we may want to keep multiple addresses
for Members (shipping and billing address) we decided to make it a class
of its own.
Library System
6
Adding Inheritance
Book
ISBN
authors
Magazine
issueNo
Member
memberNo
Copy
copyNo
Loan
checkoutDate
returnDate
Reservation
statusDate
status
LoanHistory
Author
credentials
shortBio
Address
street
city
state
zip
Person
firstName
lastName
phone
Publication
title

Library System
7
Adding Associations
Magazine
issueNo
LoanHistory
Address
street
city
state
zip
Person
firstName
lastName
phone
1 1
Mailing
1 1
Book
ISBN
authors
Author
credentials
shortBio
1..*
1..*
1..*
1..*
wrote
Member
memberNo
Publication
title
Loan
checkoutDate
returnDate
0..*
1
requests
Copy
copyNo
1..* 1 1..* 1 describes
1
0..*
1
0..*
is for
Reservation
statusDate
status
0..*
1
makes
1
0..*
1
0..*
is for
0..1
0..*
0..1
0..*
holds
{Reservation.status = "OnHold"}
0..*
1 1
0..*

Library System
8
Observations and Considerations regarding Associations

LoanHistory:
o Has no attributes and no associations.
o History of Loans is known by maintaining a list of Loan objects for each
Member.
o Hence, we don't need a separate LoanHistory class.

Publication-Copy
o Could it be a composition?
Composition is first and foremost a whole-part relationship
Does a Publication represent the whole consisting of Copies?
If you cannot answer this question with a 100% confident yes, then
it should not be a composition!
In this case, the answer then is no!
Lifetime dependency is not sufficient to choose composition. It can
be established by making the multiplicity mandatory

Item-Descriptor Pattern
o This is an analysis pattern
o It means that one class acts as a descriptor for the objects of another class
o Here we have the Publication class and its subclasses act as descriptors for
the Copy objects.

Person-Address
o Has no association name.
o It has a role name, which in this case adequately describes the relationship.
o Also, it is a one-to-one relationship and the address attributes could as
well be part of the Person class. Hence, an assocation name may not be
necessary, but still useful.

Member-Loan-Copy:
o It is not easily understood from the diagram that a Loan can only exist if a
Member and a Copy exist first and enter into a "loans" realtionships.
o It would be clearer if there were a direct association between Member and
Copy called "loans".
o However, we need to keep track of the checkout and return dates for Loan
and therefore need a class in between. checkoutDate and returnDate are
not a fact of Member or Copy. Hence, they cannot be in either class. They
are really a fact of the association between Member and Copy.
o Solution: use an association class which says that a Loan only comes into
existence when a Member and a Copy enter into a "loan" relationship.

Member-Reservation-Publication and Member-Reservation-Copy:
o See comments for Member-Loan-Copy
Library System
9
Adding Association Classes
Magazine
issueNo
Address
street
city
state
zip
Person
firstName
lastName
phone
1 1
Mailing
1 1
Book
ISBN
authors
Author
credentials
shortBio
1..*
1..*
1..*
1..*
wrote
Loan
checkoutDate
returnDate
{Reservation.status = "OnHold"}
Reservation
statusDate
status
Copy
copyNo
0..1
0..*
0..1
0..*
holds
Member
memberNo
0..*
0..*
loans
Publication
title
1..* 1 1..* 1 describes
0..*
0..*
reserves
0..*
0..*
0..*
0..*
{Copy can be ei ther on
hold or currently loaned}
{Onl y one at a t i me}

Observations and Considerations regarding Association
Classes
Multiplicity:
o When replacing two assocations with an association class the multiplicity
changes.
Library System
10
Identifying Methods (Design)

1. Which business functionality must be provided by the system (use cases)?
2. Who (which object) should be asked to provide the functionality to the user?
3. Which other objects need to collaborate to fulfill a request?


Required Functionality
Adding Publications to the library
Adding Copies for a Publication
Creating a Member

Loaning a Publication
Returning a Publication
Reserving a Publication

Cancelling a Reservation
Holding a Publication for a Reservation
Picking up a held Reservation

Library System
11
Adding Methods (Design)

Loan
checkoutDate
returnDate
returned()
Magazine
issueNo
Address
street
city
state
zip
Person
firstName
lastName
phone
1 1
Mailing
1 1
Book
ISBN
authors
Author
credentials
shortBio
1..*
1..*
1..*
1..*
wrote
{Reservation.status = "OnHold"}
Reservation
status
statusDate
cancel()
hold()
pickup()
Copy
copyNo
status
reserve()
loan()
returnIt()
hold()
0..1
0..*
0..1
0..*
holds
Publication
title
addCopy()
1..* 1 1..* 1
describes
Member
memberNo
reserve()
loan()
returnIt()
cancelReservation()
pickupReservation()
0..*
0..*
0..*
0..*
loans
0..*
0..*
0..*
0..*
reserves
{Copy can be either on
hol d or currentl y l oaned}
{Only one at a time}


Library System
12
Sequence Diagram: Loan a Copy

: Member : Copy
:Loan
: User
2: create(this, copy)
1: loan(copy)
3: setCheckoutDate()
5: setStatus("loaned")
4: loan()


Sequence Diagram: Reserve a Publication
: User
: Member
: Reservation
: Publication
2: create(this, pub)
1: reserve(pub)
3: setStatus("Pending")
4: setStatusDate(now)

Library System
13
Sequence Diagram: Cancel a Reservation
: User
: Member : Reservation : Copy
1: cancelReservation(res)
2: cancel()
3: setStatus("Cancelled")
4: setStatusDate(now)
[Copy on hold]
5: setStatus("Available")

Sequence Diagram: Return a Copy
: User
: Member : Copy : Loan : Reservation : Publication
1: returnIt(copy)
2: returnIt()
3: returnIt()
4: setReturnDate(now)
11: setStatus("available")
[has pending reservation]
[else]
6: hold()
7: hold(this)
8: setStatus("onHold")
9: setStatusDate(now)
10: setCopy()
5: hasPendingReservations()

Library System
14
Sequence Diagram: Pick up a Reservation
: Reservation
: User
: Member : Copy
1: pickupReservation(res)
2: pickup()
3: setStatus("fulfilled")
4: setStatusDate(now)
5: loan(copy)

Potrebbero piacerti anche