Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Suggestion - Addressing Primitive Obsession #48

Open
lborja04 opened this issue Jan 9, 2024 · 0 comments
Open

Refactoring Suggestion - Addressing Primitive Obsession #48

lborja04 opened this issue Jan 9, 2024 · 0 comments

Comments

@lborja04
Copy link

lborja04 commented Jan 9, 2024

Hi shoryaj98,

I trust this message finds you well. In my recent review of your code, I observed a potential instance of "Primitive Obsession" in the bill method, specifically with the use of primitive type codes to represent room types. I'd like to propose a refactoring using the "Replace Type Code with Class" technique.

Why Refactor?

Code Clarity: Using primitive type codes for room types can lead to confusion and makes the code less self-explanatory.
Maintainability: By replacing type codes with a dedicated class, the code becomes more maintainable and adaptable to future changes.

Refactoring Proposal:

public class Room {
    private double roomCharge;

    public Room(double roomCharge) {
        this.roomCharge = roomCharge;
    }

    public double getRoomCharge() {
        return roomCharge;
    }
}

public class BillProcessor {
    public static void bill(Room room, int roomNumber) {
        double amount = room.getRoomCharge();
        // ... rest of the billing logic
    }
}

// Usage:
Room luxuryDoubleRoom = new Room(4000);
Room deluxeDoubleRoom = new Room(3000);
// ... create instances for other room types

BillProcessor.bill(luxuryDoubleRoom, roomNumber);

In this refactoring, I did a rework to the Room class that encapsulates the behavior related to room types. Each room type is represented by an instance of the Room class with its specific room charge.

Feel free to consider this suggestion and adapt it to your specific needs. If you have any questions or need further clarification, please don't hesitate to reach out.

Best regards,
[Your Name]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant