Member-only story
Code refactoring challenge_1
Background
You are a lead software engineer at healthcare solution, a company specializing in healthcare management systems. The team is responsible for developing and maintaining a comprehensive application used by medical professionals to manage patient records, appointments, and billing. Recently, a new requirement emerged: to support multiple types of medical services, each with distinct billing rules and appointment scheduling logic.
Scenario
The current implementation of the billing and scheduling system has become unwieldy. The ServiceManager class, which handles both billing and appointment scheduling, has grown significantly as new types of medical services have been added. As a result, the class now contains a mix of responsibilities, making it challenging to understand, maintain, and extend.
Current Code Example:
Here is a simplified example of the problematic code:
class ServiceManager {
public double calculateBill(Service service, int hoursWorked) {
double rate = 0.0;
if (service.getType().equals("Consultation")) {
rate = 100; // Consultation rate
} else if (service.getType().equals("Surgery")) {
rate = 500; // Surgery rate
} else if (service.getType().equals("Therapy")) {
rate = 150…







