Consider the following, simplified class:
class Book {
string title;
Author author;
}
Simple enough. However, when adding methods like getBookFromDatabase(int bookId), should this be placed as a static method in this same class, or rather in a separate (i.e) BookManager–class?
Usage example:
Book b = Book.getBookFromDatabase(42);
vs.
Book b = BookManager.getBookFromDatabase(42);
I do realize that this is somewhat a matter of taste, but what is the optimal following the OOP-guidlines?
Personally, I like the “
Manager” class approach. It separates the logic, so that aBookdoesn’t have to know anything about how to acquire itself. Also,BookManagercan be a singleton here – not instantiated until one actually needs to acquire aBook.Furthermore, the
BookManagercan perform additionaly book-keeping tasks (no pun intended), such as caching, or maybe there are someBookevents to subscribe to at a global level.