i'm having a dilemma which one is better in the following case:
Movie
|
ActionMovie HorrorMovie ChristmasMovie ...
| | |
AdultActionMovie AdultHorrorMovie AdultChristmasMovie
in Movie there is a watch function, for the adult movies you need to check 18+ So i have:
void watch(viewer) {
if(check(viewer)) {
.. enjoy movie
}
else
.. you don't fit requirements
}
the check in ActionMovie HorrorMovie ChristmasMovie ...
bool check(viewer) {
return true; // nothing to check
}
the check in AdultActionMovie AdultHorrorMovie AdultChristmasMovie
bool check(viewer) {
return viewer.age >= 18; // check age
}
Now the real question is: should i just override check in the adult classes (and possible other subclasses), or should i use two traits, one which provides the normal check method (return true) which is used by ActionMovie etc, and another one (age >; 18) which is used by the adult classes?
Please provide a reason why you should pick one above the other because in my opinion these are quite the same?
Thanks.
Aucun commentaire:
Enregistrer un commentaire