I'm trying to understand the best design concept for a java POJO. If I had a car
object like so:
public class Car {
private String color;
private String make;
private String model;
private int year;
public Car(String color, String make, String model, int year) {
this.color = color;
this.make = make;
this.model = model;
this.year = year;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}
Should this car pojo have more methods in it like getGasMileage
or getTirePressure
or should those methods be put inside of a utility/interface that takes in a Car
object?
This is a design question based around a current code base using Domain Driven Design (DDD) with Entity objects that contain methods like getGasMileage
. Should a pojo/entity contain only getter/setter code or is it good practice to also contain other methods?