Sign in to follow this  

Design problem instanceof

This topic is 4391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i'm making a domotica design tool. I have the following design problem: I've got 6 domotica items (thermometer, doorsensor, pushbutton, alarmbell, jacuzzi, lightbulb) and 4 blueprintitems(wall, room, window, door). I have a blueprintItemManager who manages the blueprintitems: location(coordinate), name and owners(owner of a room are a couple of walls, owner of a window is a wall, a room and the "outside" room, the owner of a door is a wall and the two rooms it connects). The domoticaitemmanager manages the domotica items: name and owners (owner of an alarmbell is a wall, owner of a doorbutton is a door, owner of a thermometer is a wall, owner of a jacuzzi is a room). Basically, the owner of a domotica item is a blueprintitem where it can be placed on. That means that there are some rules where a domotica item can be placed. I'm trying to figure out how i can define those rules (using a good design). At the moment I have a class with a method check() and two parameters: BlueprintItem and DomoticaItem. The check method uses instanceof for the two parameters and returns true if the given domoticaitem can be placed on the given blueprint item... which I think is crap, because I don't like instanceof. I'm not seeiing another way. I don't want to make an abstract method in the superclass domoticaitem (or blueprintItem) and overloading it in the subclasses. The subclasses don't need to know where they can be placed on (and i still have to use instanceof). Anyone got an idea? Thanks, Jan (PS: I'm using java, but that is rather irrelevant)

Share this post


Link to post
Share on other sites
Maybe use composition. A given blueprint item has a list of domotica items it owns. It has addDomotica() overloaded for all the types it can own, say addDomotica(Thermometer t) and addDomotica(Wallknob k). Is that what you're after?

Edit: By the way, I don't think domotica is a valid english word ^_^.

Share this post


Link to post
Share on other sites

This topic is 4391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this