* 의존관계
- has a ->Attribute ex : 자동차 - 엔진
- 타이어
->aggregation 부엌 - 냉장고(부엌이 만들어 질때 부품들이 채워져 있지 않고 나중에 조금씩 채운다. (life cycle이 같지 않아도 된다.)
->composition - 생성될 때 다 같이 생성되야 한다.(부엌이 만들어 질때 부품들이 채워져 있어야한다.)(life cycle이 같아야 한다.)
- use a ->메소드 -사용하고 나면 없어지는것.
* has a 관계 ( 의존 관계 )
ex :
package dependency;
public class AddressDTO {
private String zipCode;
private String addressDetail;
public AddressDTO() {
}
public AddressDTO(String zipCode, String addressDetail) {
this.zipCode = zipCode;
this.addressDetail = addressDetail;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getAddressDetail() {
return addressDetail;
}
public void setAddressDetail(String addressDetail) {
this.addressDetail = addressDetail;
}
@Override
public String toString() {
return "AddressDTO [zipCode=" + zipCode + ", addressDetail="
+ addressDetail + "]";
}
}
------------------
package dependency;
public class SchoolDTO {
private String schoolId;
private String schoolName;
private String schoolTelNo;
private int enrolment;
private AddressDTO addressTo;
public SchoolDTO() {}
public SchoolDTO(String schoolId, String schoolName, String schoolTelNo,
int enrolment, AddressDTO addressTo) {
this.schoolId = schoolId;
this.schoolName = schoolName;
this.schoolTelNo = schoolTelNo;
this.enrolment = enrolment;
this.addressTo = addressTo;
}
public String getSchoolId() {
return schoolId;
}
public void setSchoolId(String schoolId) {
this.schoolId = schoolId;
}
public String getSchoolName() {
return schoolName;
}
public void setSchoolName(String schoolName) {
this.schoolName = schoolName;
}
public String getSchoolTelNo() {
return schoolTelNo;
}
public void setSchoolTelNo(String schoolTelNo) {
this.schoolTelNo = schoolTelNo;
}
public int getEnrolment() {
return enrolment;
}
public void setEnrolment(int enrolment) {
this.enrolment = enrolment;
}
public AddressDTO getAddressTo() {
return addressTo;
}
public void setAddressTo(AddressDTO addressTo) {
this.addressTo = addressTo;
}
@Override
public String toString() {
return "SchoolDTO [schoolId=" + schoolId + ", schoolName=" + schoolName
+ ", schoolTelNo=" + schoolTelNo + ", enrolment=" + enrolment
+ ", addressTo=" + addressTo + "]";
}
}
---------------------------
package dependency;
public class StudentDTO {
private String studentId;
private String studentName;
private int studentAge;
private int studentGrade;
private int studentClazz;
private int studentNumber;
private SchoolDTO schoolTo;
public StudentDTO(SchoolDTO schoolTo) {
this.schoolTo = schoolTo;
}
public StudentDTO(String studentId, String studentName, SchoolDTO schoolTo) {
this.studentId = studentId;
this.studentName = studentName;
this.schoolTo = schoolTo;
}
public StudentDTO(String studentId, String studentName, int studentAge,
int studentGrade, int studentClazz, int studentNumber,
SchoolDTO schoolTol) {
this.studentId = studentId;
this.studentName = studentName;
this.studentAge = studentAge;
this.studentGrade = studentGrade;
this.studentClazz = studentClazz;
this.studentNumber = studentNumber;
this.schoolTo = schoolTol;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public int getStudentAge() {
return studentAge;
}
public void setStudentAge(int studentAge) {
this.studentAge = studentAge;
}
public int getStudentGrade() {
return studentGrade;
}
public void setStudentGrade(int studentGrade) {
this.studentGrade = studentGrade;
}
public int getStudentClazz() {
return studentClazz;
}
public void setStudentClazz(int studentClazz) {
this.studentClazz = studentClazz;
}
public int getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(int studentNumber) {
this.studentNumber = studentNumber;
}
public SchoolDTO getSchoolTol() {
return schoolTo;
}
public void setSchoolTol(SchoolDTO schoolTol) {
this.schoolTo = schoolTol;
}
@Override
public String toString() {
return "StudentDTO [studentId=" + studentId + ", studentName="
+ studentName + ", studentAge=" + studentAge
+ ", studentGrade=" + studentGrade + ", studentClazz="
+ studentClazz + ", studentNumber=" + studentNumber
+ ", schoolTo=" + schoolTo + "]";
}
}
'프로그래밍 > JAVA프로그래밍' 카테고리의 다른 글
다형성 - 실습 (0) | 2012.07.28 |
---|---|
다형성(polymorephism) (0) | 2012.07.28 |
final변수 (0) | 2012.07.28 |
this, super키워드 (0) | 2012.07.28 |
상속, 생성자 (0) | 2012.07.28 |