I am having a bit of trouble with the design aspect of my JAVA program, there a couple of ways in which I have thought of doing, but I dont know which way is best, or if there is a better way to do it?. Below is an example of one way
<< ABSTRACT >>
Rooms class
extends extends extends
Room TYPE U Connector X Connector U
AGGREGATE walls - into each room type
The reason why I am getting a bit confused is that the 3 different types of rooms that I am using only differ in there property values(height,width etc..), but all have the same properties. Does this warrant creating a new class for EACH room type?.
Or should I do it the other way which is having the one rooms class and instantiating it three times for each room type and just changing its properties via setters and getters?.
because I would have to set each rooms properties and its aggregated wall properties which could get quite long!.
Any help is greatly appreciated.
If the rooms only differ by their property values, consider using a factory-style pattern. Here’s a simple example:
The factory methods are like “preset” constructors for different types of rooms. This strikes a balance between repetition/property setting, and having too many classes.