【发布时间】:2021-05-02 15:48:15
【问题描述】:
只是一个快速的,所以遵循开放封闭原则,如果你有这样的课程:
public class Employee extends Person {
int age;
String name;
Employee(int age, String name) {
super(age, name)
}
// Getters and setters follow
}
如果你想添加一个额外的字段,比如说一个地址,这会不会违反 Open/Closed 原则?
只是好奇你这样做是否违反了这个原则,你将如何创建类来解决这个问题?
谢谢
【问题讨论】:
标签: java solid-principles open-closed-principle