vendredi 30 décembre 2022

OOD Hotel Management System

i´m Developing a Hotel management system, and i think my current approach about the booking process is wrong, i was wondering if someone could help me design it, so it uses good design principles. I dont feel confident about the bookRoom() method in the Client class, This is the code:

public class Client {
    private String name;
    private String surname;
    private List<Reservation> clientReservations;

    public Client(String name, String surname) {
        this.name = name;
        this.surname = surname;
        this.clientReservations = new ArrayList<>();
    }
    //Should Go Getters and Setters
  
    public void bookRoom(LocalDate startDate, LocalDate endDate, Room room) {
            Reservation reservation = room.addReservation(startDate, endDate, this);
            clientReservations.add(reservation);
    }

----------------------------------------------------------------------

public class Room {
    private String roomID;
    private Category category;
    private int price;
    private List<Reservation> reservations;

    public Room(String roomID, Category category, int price) {
       //Set the values
    }

  //Should Go Getters and Setters


    public Reservation addReservation(LocalDate startDate, LocalDate endDate,Client client){
        if (!isReserved(startDate,endDate)) {
            Reservation reservation = new Reservation(this, startDate, endDate, client);
            reservations.add(reservation);
            return reservation;
        }
        return null;
    }


----------------------------------------------------------------------


public class Reservation {
    private Client client;
    private Room room;

    private LocalDate startDate;

    private LocalDate endDate;

    public Reservation(Room room,LocalDate startDate,LocalDate endDate,Client client) {
        this.room = room;
        this.client = client;
        this.startDate = startDate;
        this.endDate = endDate;
    }

    public Room getRoom() {
        return room;
    }

    public Client getClientName() {
        return client;
    }

    public LocalDate getStartDate() {
        return startDate;
    }

    public LocalDate getEndDate() {
        return endDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Reservation that = (Reservation) o;
        return client.getName().equals(that.client.getName()) && room.getRoomID().equals(that.room.getRoomID());
    }

    @Override
    public int hashCode() {
        return Objects.hash(client, room);
    }


}

I tried to apply ood principles, but i am still a little bit lost about the design, i dont feel it flexible.

Aucun commentaire:

Enregistrer un commentaire