- #1
lavster
- 217
- 0
im a bit confused - please help - I am a complete beginner!
I have several classes, within which are several attributes defined and declared.
The assocation between some of these classes are aggregation, and between others is compostion.
Take the example of person and car being and aggregation composition and car and wheels being a composition relation. In the wheel class i have a List object defined and instantiated as "allwheels". (ie private List allwheels = new ArrayList). This is basically a collection of all the wheels of car, which is already defined and declared in the wheel class as wheel_fl wheel_fr etc. In my car class i want to call in and use the allwheels (remember this is in the wheel class). However, i get errors as the car class does not know what allwheels is as its part of wheel class and not declared and defined in the car class. However, i need the method using allwheels in the car class and i need allwheels defined and instantiated in wheels class.
How would i get round this problem??
I have tried many things which don't work. now I am thinking (in my head - haven't a clue what it would do in a programming sense) the simplest would be to have a line at the top of my car class (ie in public class car {}) that says:
private List allwheels;
However, my relationship between the two classes NEEDS to be a composition. If i insert this line will it become an aggregation?? My naive understanding is that if the line has "=new" then its compostion and if it doesn't have an equal sign it is an aggregation and so i couldn't do this as it would become an aggregation? is this correct?? if so, could you give me any pointers as to how to call in allwheels but keeping it a composition relation?
Thanks in advance :)
I have several classes, within which are several attributes defined and declared.
The assocation between some of these classes are aggregation, and between others is compostion.
Take the example of person and car being and aggregation composition and car and wheels being a composition relation. In the wheel class i have a List object defined and instantiated as "allwheels". (ie private List allwheels = new ArrayList). This is basically a collection of all the wheels of car, which is already defined and declared in the wheel class as wheel_fl wheel_fr etc. In my car class i want to call in and use the allwheels (remember this is in the wheel class). However, i get errors as the car class does not know what allwheels is as its part of wheel class and not declared and defined in the car class. However, i need the method using allwheels in the car class and i need allwheels defined and instantiated in wheels class.
How would i get round this problem??
I have tried many things which don't work. now I am thinking (in my head - haven't a clue what it would do in a programming sense) the simplest would be to have a line at the top of my car class (ie in public class car {}) that says:
private List allwheels;
However, my relationship between the two classes NEEDS to be a composition. If i insert this line will it become an aggregation?? My naive understanding is that if the line has "=new" then its compostion and if it doesn't have an equal sign it is an aggregation and so i couldn't do this as it would become an aggregation? is this correct?? if so, could you give me any pointers as to how to call in allwheels but keeping it a composition relation?
Thanks in advance :)