Search⌘ K

Develop the Mock Service

Explore how to develop a mock service for class table inheritance scenarios by implementing add, create, retrieve, remove, and edit operations on an in-memory database. Understand the use of the singleton pattern and how the service connects with controllers to manage EmployeeDto subtypes, preparing you for integrating user interfaces later.

add function

Let’s begin with a simple add method to the in-memory database. This is based on the Singleton pattern implemented as an enum.

Java
public enum EmployeeInMemoryDB {
INSTANCE;
private static List<EmployeeDto> list = new ArrayList<EmployeeDto>();
private static Integer lastId = 0;
public Integer getId() {
return ++lastId;
}
public void add(EmployeeDto employeeDto) {
employeeDto.setId(getId());
list.add(employeeDto);
}
}

Create operation

We will look at the mock service for the create ...