Design patterns 现在比以前需要更多参数的设计接口
解释用例:Design patterns 现在比以前需要更多参数的设计接口,design-patterns,Design Patterns,解释用例: public class Course { Mathematics math; Physics physics; English english; String teacher; String schoolName; //Just want explaing modelling hence keeping } public class PhysicsHelper extends Helper { public void help(Ph
public class Course {
Mathematics math;
Physics physics;
English english;
String teacher;
String schoolName; //Just want explaing modelling hence keeping
}
public class PhysicsHelper extends Helper {
public void help(Physics physics, String teacher) {
Course course = // create course
help(course);
}
}
public class MathematicsHelper extends Helper {
public void help(Mathematics math, String teacher, Address address) {
String schoolName = address.getSchoolName
Course course = // create course
help(course);
}
}
public abstract class Helper {
public void help(Course couse) {
// defualt set of operations to be called by all helpers.
}
}
现在,我有一个要求,比如:
PhysicsHelper也开始理解英语了,
所以现在PhysicsHelper有了方法
public class PhysicsHelper extends Helper {
public void help(Physics physics, String teacher, English english) {
}
}
正如@Charles Follet所建议的,最好在
PhysicsHelper.class
中重载help(…)
方法,而不是在一个方法中处理所有可能的主题。此外,您还可以制作课程。课程只包含所有当前科目的共享字段
public class Course {
String teacher;
String schoolName; //Just want explaing modelling hence keeping
}
public class EnglishCourse extends Course {
English english;
}
public class PhysicsCourse extends Course {
Physics physics;
}
public class PhysicsHelper extends Helper {
public void help(Physics physics, String teacher) {
}
public void help(English english, String teacher) {
}
}
你最好延长英语和物理课程。然后你可以打两次电话求助。每门课程一次。我希望您不要为助手理解的每一件事情添加参数。