Thing vs Item

Topics: Code
Coordinator
Feb 26, 2008 at 4:08 AM
Foxy,

I'm in the process of designing a sort of factory to create world items from the database. I noticed that there is no consistency in the classes inside the Things folder. Some of them are Thing, while others are Item. That makes it a bit hard to do a proper factory, meaning without having to do some severe hack/kludges. I could come up with something, if I knew what was the idea behind the creation of the Thing/Item classes. They sort of look like scatter shot right now, but that is probably because is late at night and I'm quite tired. :p
Feb 26, 2008 at 3:59 PM
I havent got the code in front of me right now, but doesnt Item inherit from thing or implement IItem which implements IThing?

Ill have a look when i get home
Coordinator
Feb 27, 2008 at 5:12 PM
Edited Feb 27, 2008 at 5:24 PM
After much cogitating, it looks like I'm going to go with the Builder Pattern. http://www.dofactory.com/Patterns/PatternBuilder.aspx This should future-proof our items for stuff like:
  • Items that leave pieces when they break
  • Items made of different materials
  • Injecting item behaviors depending on what's being created
  • Items with constructors, like the portals
All we would need to change would be the specific director and concrete builder for whatever is being changed. I'm hoping to get this done in the next few days.
Feb 28, 2008 at 10:39 AM
Sounds good to me!