英文:
Java UML implementation
问题
以下是您要翻译的内容:
如何在Java中实现类似的内容?
目前我有这个:
public class Person {
String name;
String surName;
Integer yearOfBirth;
// 构造函数、获取器、设置器和方法
}
public class Professor extends Person {
String department;
// 构造函数、获取器、设置器和方法
}
// Professor的两个子类
public class DepartmentProfessor {
String departmentName;
// 构造函数、获取器、设置器和方法
}
我对UML非常新手,如果我理解正确的话,Professor必须是一个接口,DepartmentProfessors必须实现它,但是我有一个问题,Person是一个超类,有具体的方法,Professor有两个子类。
英文:
How I should make something like that in Java?
Right now I've this:
public class Person {
String name;
String surName;
Integer yearOfBirth;
//Constructors, Getters, Setters and Methods
}
public class Professor extends Person {
String department;
//Constructors, Getters, Setters and Methods
}
// Two Childs of Professor
public class DepartmentProfessor {
String departmentName;
//Constructors, Getters, Setters and Methods
}
I'm very newbie to UML, if I understood correctly, Professor has to be an interface and DepartmentProfessors have to implement it but then I've the problem of Person being superclass, have concrete methods, of Professor and it having two subclasses.
答案1
得分: 2
你误解了。Professor
是一个简单的类,DepartmentedProfessors
也是一样。只不过后者依赖于前者(虚线箭头线所示)。这是因为 Professor
在操作 addProfessor(Professor)
的参数中被使用。
英文:
You are mistaken. Professor
is a simple class and DepartmentedProfessors
the same. Only that the latter depends on the first one (the dashed arrow line). This is because Professor
is used in a paramter of the operation addProfessor(Professor)
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论