Mastering OOD: Hotel System UML with VPasCode & PlantUML

PlantUML diagram showing Hotel Management System class and interface architecture

Designing robust software systems requires a clear blueprint of how different components interact. In the realm of Object-Oriented Design (OOD), the Unified Modeling Language (UML) Class Diagram is the cornerstone of architectural planning. It visually represents the system’s static structure, defining classes, their attributes, methods, and the complex relationships that bind them together.

In this tutorial, we will explore how to build a sophisticated Hotel Management System using PlantUML within the VPasCode environment. We will move from defining high-level interfaces to implementing concrete classes, demonstrating how to use abstraction and inheritance to create scalable, maintainable code structures.

1. Defining the Architecture: Interfaces and Abstraction

Before writing concrete code, a good architect defines the “contract” or behavior of the system through interfaces. In our hotel scenario, a reservation must be bookable, and a transaction must be payable. These are distinct responsibilities that should be modeled as interfaces.

Defining the IReservable Interface

The IReservable interface dictates the actions required to manage a booking. It ensures that any class implementing this interface must handle the lifecycle of a reservation.

@startuml
title Hotel Management System

' Define interfaces
interface IReservable {
    + makeReservation(customer: Customer, dates: DateRange): boolean
    + cancelReservation(reservationId: String): boolean
    + checkAvailability(date: Date): boolean
}

Defining the IPayable Interface

Financial transactions are critical. The IPayable interface standardizes payment processing across different parts of the system.

interface IPayable {
    + processPayment(amount: double): boolean
    + issueRefund(reservationId: String): boolean
    + getPaymentStatus(): String
}

2. Abstracting Commonality: The Person Class

In object-oriented design, abstraction is key to reducing redundancy. Both Customers and Staff share common attributes like ID, Name, and Contact Information. Instead of duplicating this code, we create an abstract class named Person.

An abstract class acts as a blueprint. It can contain both implemented methods (like getContactInfo()) and serve as a parent for concrete classes.

abstract class Person {
    - id: String
    - name: String
    - email: String
    - phone: String
    + getId(): String
    + getName(): String
    + getContactInfo(): String
    + updateContactInfo(info: String): void
}

3. Building Concrete Entities: Room, Customer, and Reservation

Now we define the concrete entities that the system will manage. These classes inherit from the abstract Person or implement the previously defined interfaces.

The Reservation Class

The Reservation class is the heart of the system. It combines the logic of being bookable (IReservable) and payable (IPayable). It manages specific data such as checkInDate, totalPrice, and the ReservationStatus.

class Reservation {
    # reservationId: String
    # checkInDate: Date
    # checkOutDate: Date
    # totalPrice: double
    # status: ReservationStatus
    # specialRequests: String
    + calculateTotalPrice(): double
    + confirmReservation(): void
    + checkIn(): void
    + checkOut(): void
    + updateDates(newCheckIn: Date, newCheckOut: Date): boolean
    + getDuration(): int
}

The Customer Class

Extending the abstract Person class, the Customer class adds domain-specific logic. Notice the addition of loyaltyPoints, a common feature in hotel management systems.

class Customer extends Person {
    # loyaltyPoints: int
    + getId(): String
    + getName(): String
    + getContactInfo(): String
}

The Room Class

Rooms are the inventory of the hotel. This class defines the capacity and type of the room.

class Room {
    # roomNumber: String
    # roomType: String
    # capacity: int
}

4. Visualizing Relationships and Dependencies

A diagram is only as good as its relationships. The visual representation in VPasCode clarifies how these classes interact.

  • Implements: The Reservation class implements both IReservable and IPayable. This is shown using a dashed line with a hollow triangle arrow pointing to the interface. This enforces the rule that a Reservation must have the methods defined in those interfaces.
  • Extends: The Customer class extends Person, inheriting all its attributes and methods.
  • Aggregation (Contains): A Room “contains” a Reservation. This is depicted by a line with an open diamond at the Room end, indicating a “has-a” relationship.
  • Association (Makes/Booked By): Customer makes a Reservation, and a Reservation is booked by a Customer. The multiplicity labels (1..*) indicate that one customer can make many reservations, and a reservation is linked to at least one customer.

Conclusion

By leveraging the VPasCode tool, we have transitioned from simple text definitions to a dynamic, interactive UML Class Diagram. This approach allows you to visualize the implementation of IReservable and IPayable interfaces against the concrete Reservation class, ensuring your hotel management system is architected with clean separation of concerns.