Child pages
  • Hotel mixin sample -- accommodation mixin
Skip to end of metadata
Go to start of metadata

(The accommodation mixin includes basic billing)

This slice of the software

  • remembers who has been accommodated in which room
  • keeps track of consumption of beverages (beer and soda)

Each week and each occupied room is represented by an instance of
AccommodationInfo in the repository and stores the name of the guest (assumed
to be unique) and the room number where he or she has been
accommodated for the week. Consumption is reported every morning
by the cleaning lady, who also refills the fridge in the room.

This slice is more or less orthogonal to making reservations, but note
that actually accommodating a guest who has reserved a room
requires to move his data from the Repository<IReservationInfo>
to the Repository<IAccommodationInfo>. For this reason, the
AccommodationMixin depends on the ReservationMixin, but
keep in mind that the AccommodationMixin extends Hotel.Base, not
the ReservationMixin. (Look at the diagram above again, if this
confuses you.)

The AccommodationMixin holds an instance of the
Repository<IReservationInfo> and exposes the following simple
methods. They work in analogous manner as their counterparts in
the ReservationMixin:

                  
- bool IsRoomFree (int number)
- int? FindFreeRoom ()                   // returns null if none is found
- IAccommodationInfo Find (string name)  // ditto

(Just as in the reservation mixin, CountAccommodations ()
and ClearAccommodations () are not part of the interface,
because they are support for testing.)

As explained before, an accommodation can be understood as a
reservation for the current week. For this reason, IsRoomFree,
FindFreeRoom and Find don't sport a week-parameter, as their
siblings in the ReservationMixin do.

IsRoomFree has a twist, because it must make sure

  • that there is no reservation for the room and the current week
    (after all, it might be waiting for being claimed by the reserving party

AND

  • that the room is not occupied by another guest already (this part is handled by the method IsRoomFreeOfAccommodation)

(An alternative implementation would set and clear
the corresponding reservation info for the current week
whenever someone is accommodated.)

In code:

    public virtual bool IsRoomFreeOfAccommodation (int number)
    {
      return _accommodationRepository.Find ().Count (accInfo => accInfo.Number == number) == 0;
    }

    public virtual bool IsRoomFree (int number)
    {
      return Base.IsRoomFree (number, Calendar.Week ()) && IsRoomFreeOfAccommodation (number);
    }

FindFreeRoom () and Find ultimately look into the accommodation repository,
what is more or less analogous to the reservation mixin's methods of the same names.

In code:

    public virtual int? FindFreeRoom ()
    {
      for (int iter = 0; iter < Hotel.Base.Hotel.NumberOfRooms; iter++)
      {
        if (IsRoomFree (iter))
        {
          return iter;
        }
      }
      return null;
    }

    public virtual IAccommodationInfo Find (string name)
    {
      return _accommodationRepository.Find ().SingleOrDefault<IAccommodationInfo> (elem => elem.Name == name);
    }

The analogous operations to Reserve and Cancel are
Accommodate and CheckOut. Accommodate giveth, CheckOut taketh,
just like Reserve and Cancel. More deja-vus:

  • Accommodate throws an exception if no rooms are available
  • Accommodate throws an exception if the name for accommodation already is in the repository
  • CheckOut throws an exception if the cancelee can't be found in the repository

Apart from that, CheckOut returns an amount of money as decimal,
i.e. the Total as computed by the Bill.

  • No labels