I am new to Java so I am trying to get my head around some of the concepts of Java, so be gentle with me!.
I have my main MASTER CONTROLPANEL CLASS which contains the main of the program, and I Insantiate the building class which contains instances of the rooms class,
and the rooms class contains instances of the walls class,
and the walls contains instances of the windows class.
Basically constructing the building, each instantiation of the rooms class will have different amount of instances of walls, and walls different amount of windows, primitive height and widths etc..
What is the best way to go about the design of this?, as in creating the dynamic amount of walls and windows, is the only way with accessor methods? and just altering the measurements in the MAIN of the program? or having a method to add each wall individually to an arraylist for each room? and if so where is the best place to place these?
Thanks very much for any help.
Follow the rule of thumb.
Wherever your problem definition has
has-a, you got composition. If you are going tohas-many, you may use a Collection — as you said,Listof walls, andListof windows.You may also, abstract stuffs, have
Windowas abstract class and can use implementation forStandardWindoworManSizeWindow— this is ais-arelationship. as inStandardWindowis aWindow. You are likely to have this kind of stuff in your problem where you are required to decorate the rooms with same kind of stuff but different properties.Also, do not use rigid code, like have classes that have, say, three windows attributes and three getters/setters them. You are likely to regret later with this technique.