Hotel mixin sample -- discount mixin mixin

Guests who show up for the 3rd time get a 10% discount. (Values can be configured by modifying const|s in the source-code.)

This slice is an extension to the accommodation and billing slice (see FIXME). The method CheckOut (see above) computes the price of the accommodation, so it is intercepted by the discount supplement, which looks into a history of accommodations and subtracts a discount, if applicable. What's more, the overriding (intercepting) CheckOut increments the accommodation counter for the given name in the _discountInfoRepository.

In code:

    [OverrideTarget]
    public decimal CheckOut (IAccommodationInfo accommodationInfo)
    {
      _discountInfoRepository.Add (new DiscountInfo (accommodationInfo.Name));

      var total = Base.CheckOut (accommodationInfo);

      if (CountPastAccommodations (accommodationInfo.Name) % DiscountVisits == 0)
      {
        return total * (100 - DiscountInPercent);
      }
      else
      {
        return total;
      }

    }

Note that the _discountInfoRepository is not a repository, because a Dictionary is simpler. In a more lovingly rendered implementation of the repository pattern, the accommodation history would be a by-product of a well-designed database schema.

The class DiscountMixinMixin extends/intercepts the AccommodationMixin and provides the logic for the discount slice. It overrides only the CheckOut method. Again, two utility methods are used for testing:

  • int CountPastAccommodations () // count ALL accommodations in the _discountInfoRepository
  • int CountPastAccommodations (string name) // count them for the given name