I am a newbie in object oriented design. While reading, a question came to my mind and I couldn't decide what design pattern to use (or should i use it at all).
For example, in the library, the due dates of the books depend on both the books and the people. If the book is rare, the due date should be less than other books, or if the person is a frequent customer, the due date should be longer. So this feature accessesing the attributes of both classes, where or how would it be more correct to add it?
I thought of different scenarios and interpreted the pros and cons as follows:
-
Creating an interface named due date and ensuring that both classes (Book and Customer) implement it. But where can I merge two dates like this? For example, if the due date for the book is 2 weeks and 1 week is added due to the customer's characteristics, where should the result of 3 weeks appear?
-
Creating a separate class and sending instances of two objects as parameters to a method. In this case, creating a new class for each feature to be added (due date calculation in this example) seems to be a very tedious task.
Aucun commentaire:
Enregistrer un commentaire