--------- ---------
| | * * | |
| Person |________________| Company |
| | | | |
--------- | ---------
|
______|______
| |
| |
| Employment |
| |
|_____________|
I try to design a classes with association class in JAVA , but i don't understanding how to use the association class in implementation .. but I understanding the benefits for it.
this what I try to do it :
public class person {
protected employment emp;
.
.
}
public class company {
protected employment emp;
.
.
}
public class employment {
protected person p[];
protected company c[];
.
.
}
Is the relationship and the implementation is correct ?
No, the multiplicity is on references to employment.
Note that Java naming convention is for class names to start with uppercase letter.
Java arrays are fixed-size, so it's better to use List, so you can easily add more employments.
In general, fields should be private.
public class Person {
private List<Employment> employments;
.
.
}
public class Company {
private List<Employment> employments;
.
.
}
public class Employment {
private Person person;
private Company company;
.
.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With