添加新类的设计模式
我有两个班级,学生和教师,学生有一个具体方法:takeCourse;老师有一种具体的方法:teachCourse。
现在我想添加一个新的班级,GradStudent,它可以像Student一样上课,也可以像Teacher一样教授课程。哪种模式是实现这个新类的最简单方法?适配器、复合、委托......?
谢谢。
I have two classes, Student and Teacher, Student has one concrete method: takeCourse; Teacher has one concrete method: teachCourse.
Now I want to add a new Class, GradStudent, which can take course, like Student, and also can teach course, like Teacher. Which pattern is the easiest way to implement this new class ? Adapter, Composite, Delegate .... ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题应该是对此进行建模的最佳方式是什么,答案是“在现实世界中有意义的方式”,即研究生也可以教学和参加课程;-)
不要试图将所有内容与现实世界联系起来。设计模式。坚持我们在学校学到的基本原则“类对现实世界的对象进行建模”,“让模型接近现实世界”
The question should be what is the best way to model this for which the answer would be "the way it makes sense in the real world" i.e. A Grad student can also teach and take course ;-)
Do not try to relate everything to the design patterns. Stick to the basic principle that we learnt in school "Classes model real world objects", "Keep the model close to the real world"