scrom / Experiments

a NodeJS text adventure - deliberately coded badly to re-experience the pain of legacy code
http://mvta.herokuapp.com/
2 stars 0 forks source link

Clean up "get/add/remove" object behaviour #108

Open scrom opened 10 years ago

scrom commented 10 years ago

back to single responsibility again. "removeObject" tried to do too much and ties us in knots elsewhere.

When transferring an object form a location, creature or player to another, the pattern to follow should be getObject (to get it's details) verify it exists test that it can be transferred remove the object from the source add the object to the destination.

The add and remove need a "transfer" function that adds and removes with all validation removed so that these are guaranteed to succeed without "losing" or duplicating objects.

This means we need to rely on much more validation - maybe with a "canTransfer" function first.

Either way it needs cleaning up. This should also help with inventory object bleed across other objects.

scrom commented 10 years ago

this is improving through use of inventory object but still needs more work

scrom commented 10 years ago

this is a bit dodgy still. There's a lot of places where the underlying inventory object needs to be exposed to the caller at the moment.