Question

In my program a collection of "Book" objects is held by a "Shelf" object, which a series of are held by a "Library" object.

Each "Shelf" holds a certain amount of books. Currently, I have a "Reference" book to identify the Book the shelf can hold. Each "Shelf" has an ArrayList of copies of the same book that refer to unique objects identical to the "Reference" book.

When I transfer a book in the shelf to a user, should I transfer an entire instance of the "Book" and its reference variable and delete the reference variable to that instance from the shelf?

Or...

Should I keep track of the amount of books left with an int variable and simply make copies of the reference variable to the "Reference" book to the user?

In an essence...

Liberal memory use vs. Conservative

Physical transfer vs. Conceptual

respectively.

Was it helpful?

Solution

Presumably library books have a fixed place on a shelf?

In which case I would simply mark a book as checked out and record the date when the book is due back and a reference to the user who checked it out.

On the user side, they can have a List of books that they have currently checked out. This is a one-to-many relationship.

This way when the user checks the books back in you just need to flip some flags, you do not need to search for where the book "goes" on the shelf.

If you are trying to model a library however then the former approach would seem more applicable...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top