2 ms·
As a non-OOP-thinker, this seems completely natural to me. The verb hit doesn't belong completely to one noun, so it shouldn't be forced to live within the stru
by iguy 8y ago
As a non-OOP-thinker, this seems completely natural to me. The verb hit doesn't belong completely to one noun, so it shouldn't be forced to live within the struct/class with the data (which really is about only that noun).
What problem is solved by forcing the function to belong to one of the actors, as in joe.hit(tiger).with(sword) or something? People say things about encapsulation, but it seems here that hit may change the state of Player, Monster and Weapon, so their states can't be fully private. In this code you can also have hit(p::Player, w::Door), if this were not allowed then perhaps you'd have to have separate hit_player_monster and hit_player_door functions... is that the problem?