Java实体类(entity)
一、前言(项目代码引申)
在一个开发的android项目中,使用到了Entity类
其中SecurityDomain是一个架构模板可忽略,其余四个Entity类是根据实际功能需求扩写的,项目中这四个实体类在(1)对应的Fragment类(2)Repository(3)VehicleViewModel中使用。
这四个Entity类中包含构造方法,对应开关(Switch)的功能写了is和set方法,对应设置选项的功能写了get和set方法。
set ,get完全是自我规定的,就是设置初值和获得值的意思.你也可以修改成其他字符.但是用set ,get还是要好些,因为你能通过单词理解你写的代码的意思,方便阅读而已。
这边以包含了is,set,get方法的CommonEntity为例,看一下代码:
public class CommonEntity {
private int drivingMode;
private int lampMode = -1;
private boolean epbRelease;
private boolean escSwitch;
private boolean autoHoldSwitch;
public CommonEntity(int drivingMode, int lampMode, boolean epbRelease, boolean escSwitch, boolean autoHoldSwitch) {
this.drivingMode = drivingMode;
this.lampMode = lampMode;
this.epbRelease = epbRelease;
this.escSwitch = escSwitch;
this.autoHoldSwitch = autoHoldSwitch;
}
public boolean isEscSwitch() {
return escSwitch;
}
public void setEscSwitch(boolean escSwitch) {
this.escSwitch = escSwitch;
}
public boolean isAutoHoldSwitch() {
return autoHoldSwitch;
}
public void setAutoHoldSwitch(boolean autoHoldSwitch) {
this.autoHoldSwitch =