3 ms·
I'm pretty confused by how you perceive this. I don't see "crap boilerplate supporter classes" – I see objects that encapsulate events and actors for all the us
by matthewmacleod 8y ago
I'm pretty confused by how you perceive this. I don't see "crap boilerplate supporter classes" – I see objects that encapsulate events and actors for all the usual OOP reasons.
I wonder if some of this disagreement is down to the way that different people abstract this problem in their heads.
- jstimpfle 8y ago// player.hits(monster).with(weapon) add to class Player { // XXX: Bad coupling Player -> Monster // XXX: Bad coupling Player -> PlayerMonsterHit method hits(Monster monster) { return PlayerMonsterHit(player, monster) } } class PlayerMonsterHit { member Player player; member Monster monster; construct PlayerMonsterHit(Player player, Monster monster) { this.player = player; this.monster = monster; } method with(Weapon weapon) { doTheActualFrigginHit(this.player, this.monster, weapon); // this line is all we REALLY need } } I guess 15 lines (that do NOTHING) was not an overestimation.
- matthewmacleod 8y agoThey don't "do nothing" - they define structure that can then be used to handle more implementation later. It's a ridiculous, contrived example, and you know that. Yes – this code is stupid if all you need to implement is a single line with the ability for a player to hit a monster. But that's never what you are implementing, is it?
- jstimpfle 8y agoIf you want to delay the hit, i.e. transactioning / buffering / delaying: This is sound engineering! But that part is not even included in above boilerplate. It would be: struct PlayerMonsterWeaponHit { Player player; Monster monster; Weapon weapon; } Array<PlayerMonsterWeaponHit> playerMonsterWeaponHits; doTheActualFrigginHit(Player player, Monster monster, Weapon weapon) { playerMonsterWeaponHits.emplace(player, monster, weapon); } In case it isn't obvious you can do that with either implementation, the above OOP boilerplate or the above imperative 1 line of code. > Yes – this code is stupid if all you need to implement is a single line No, it's stupid because it doesn't do anything. The data structures are only for temporaries that will never have any other use. In the end it's going to be PlayerMonsterWeaponHit. So the other classes are just stupid, and no amount of context will change that.