I have below classes.
public class BaseRequest {
protected List<Emp> names; // names property is required in many classes
}
public class FirstRequest extends BaseRequest {
public FirstRequest() {
names = new ArrayList<Emp>();
}
public setNames(List<Emp> names){
super.names = names;
}
public List<Emp> getNames(){
return super.names;
}
}
public class ServiceClass {
public void someMethod(List<Emp> emps) {
FirstRequest request = new FirstRequest();
request.setNames(emps);
//Some Logic
}
}
Am i doing inheritance in right way? how i can i improve it further?
Thanks!
BaseRequest request = new FirstRequest();instead ofFirstRequest requestin side theServiceClassnamesdefined inBaseRequestbut the setter and getter as well as the initialization inFirstRequest? There might be reasons for this but unless it's on purpose, move that code toBaseRequestas well.