Squishing bugs

In the past week I mainly concentrated on squishing old bugs that have been lurking around way too long. Most of them were actually easy after sitting down and looking them properly. But there’s one (#38, to be precise) that wasn’t like that. Easy on the surface and should have been cleared in 5 minutes, but after poking around it a bit I had to conclude otherwise. There’s two classes called Damage in the game. One of them is used to create status effect that damages the target while other one is used to represent damage taken in combat. The latter one has code that takes damage modifiers into account (resistances and weaknesses in particular) and handles armour too. The first one has just a simple subtraction of hit points that should be fixed.

Since I like to keep amount of duplicated code in minimum, I extracted resistance and armour logic into a separate class that I placed in rules package (since that’s where it should go, right?). Of course this in the end caused a circular reference because rules are referencing the model (where damage effect is located) and model is referencing rules where new class for resistances and armour handling is now located. On top of that I tried to rename Damage to DamageEffect to make it easier to distinguish it from the Damage that is used to represent damage in combat. The end result was too big refactor in one go that didn’t work at all. So in the end I rolled everything back and started proceeding with smaller steps: first renaming Damage to DamageEffect and then continuing with rest of the changes.

I probably will place the new damage class in the model package even, since it’s more of a value object in the end after all. Whole division to model vs. rules is sometimes a bit unwieldy anyway, I really should look into that more at some point. Now the model is a bit anemic and some people consider that to be an anti-pattern.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s