I am having a confusion regarding object modeling, which I will illustrate using a simple lending library project.
The library has books (one copy for each book to keep things simple) and patrons. Patrons can loan a book, if that book is not loaned to another patron.
This will need 3 classes, Book, Patron and Loan.
Book will have an id and a name. Patron will have an id and name. Loan will have an id, book_id, patron_id and loan date.
Where will the loan and return method be defined? Is this a method of book, patron or loan object?
Book is the one getting lended, patron is the one who lends the book and loan is the one who keeps all details about the particular lending operation.
Why is Loan class really needed? Of course the DB table is needed with the fields mentioned above, but from an MVC framework perspective (eg: Symfony or Rails) should this be defined as a model?
I know this is a simple and solved problem, but after being out of touch with oop design for long, I am not quote able to "view" this problem correctly!
Make a class that is responsible for creating a Loan object. You could call this LoanCreator or if it is helpful for you to think of it in the following way you could call it Librarian. You would pass this new class a Book and a Patron object and it would create the Loan for you. Generally if you find yourself unsure if a method should belong to a particular class then perhaps it is time to consider creating a new class.