I am creating a library program. Should I transfer

2020-05-02 05:34发布

问题:

In my program, I books are objects and these books are kept in a shelf object which is kept in a library object. Inside the shelf object, I have a "reference" book that says what book the shelf is holding. But I also have an ArrayList that holds separate instances of the "reference" book. Again, it holds many reference variables that reference unique objects, they do not all reference the "reference" book.

So my question is... When transferring a book to a user, should I be transferring each unique reference variable to the user and deleting the reference variable out of the list? or.... Should I scrap the list and just copy pointers of the "reference" book to the users?

Note: A shelf has a set number of books that can be removed from it. I realize that the first choice would be a waste of memory. Also, in the second choice, I would just be keeping track of the amount of books left using an int variable. I would not be keeping track of the amount of book objects possessed by that shelf.