Member-only story
Senior Java Software Developer Interview Questions — part 1
3 min readFeb 18, 2023
Part 2, Part 3, Part 4
1. Anemic Model vs Rich Model ?
Anemic Model refers to a design where the data model is primarily composed of data structures, and the business logic resides outside of the model, typically in services or managers. In other words, an Anemic Model is a model with an emphasis on data rather than behavior.
public class Order {
private Long orderId;
private String customerName;
private String shippingAddress;
private List<OrderItem> items;
}
public class OrderService {
public double calculateTotalPrice(Order order) {
// business logic for calculating total price
}
public boolean checkInventory(Order order) {
// business logic for checking inventory
}
}
On the other hand, Rich Model refers to a design where the model not only includes the data structures but also the business logic related to that data. In other words, a Rich Model is a model with an emphasis on both data and behavior.
public class Order {
private Long orderId;
private String customerName;
private String shippingAddress;
private List<OrderItem> items;
public double calculateTotalPrice() {
// business logic for calculating total price
}…