Sitemap
Dev Nectar

Your go-to guide for mastering system design, data structures, algorithms, AI, GPT, and LLM skills

Member-only story

Code refactoring challenge_1

--

Press enter or click to view image in full size

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…

--

--

ScalaBrix
ScalaBrix

Written by ScalaBrix

System Design & Architecture | 🚀 Next-gen architecture content | 📈 Built for scale | Tech Blog https://www.youtube.com/@ScalaBrix/videos

Dev Nectar
Dev Nectar

Published in Dev Nectar

Your go-to guide for mastering system design, data structures, algorithms, AI, GPT, and LLM skills