Created
November 24, 2023 14:10
-
-
Save sunmeat/6fd5abfd07695a9ab0ab15ab626bbfa0 to your computer and use it in GitHub Desktop.
facade C# example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SkiRent // аренда снаряжения | |
{ | |
public double RentBoots(int feetSize, int skierLevel) // ботинки | |
{ | |
double price = 159.99; | |
// if (feetSize < 40) price -= 20; // скидка для детей | |
return price; | |
} | |
public double RentHelmet(int headSize, int skierLevel) // шлем | |
{ | |
return 120; | |
} | |
public double RentSki(int weight, int skierLevel) // лыжи | |
{ | |
return 180; | |
} | |
public double RentSkiPoles(int height) // лыжные палки | |
{ | |
return 50; | |
} | |
} | |
// https://bukovel24.com/ru/skipass | |
class SkiResortTicketSystem // покупка билетов | |
{ | |
public double BuyOneDayTicket() | |
{ | |
return 1100; | |
} | |
public double BuyTwoDaysTicket() | |
{ | |
return 2050; | |
} | |
public double BuyThreeDaysTicket() | |
{ | |
return 2900; | |
} | |
public double BuyFourDaysTicket() | |
{ | |
return 3800; | |
} | |
public double BuyFiveDaysTicket() | |
{ | |
return 4600; | |
} | |
public double BuySixDaysTicket() | |
{ | |
return 5150; | |
} | |
public double BuySevenDaysTicket() | |
{ | |
return 5800; | |
} | |
} | |
// https://bukovel24.com/uk/hotels | |
class HotelBookingSystem // заказ гостиницы | |
{ | |
public double BookRoom(int roomQuality) | |
{ | |
switch (roomQuality) | |
{ | |
case 3: | |
return 5670 / 2; | |
case 4: | |
return 9240 / 2; | |
case 5: | |
return 41500 / 2; | |
default: | |
throw new ArgumentException("roomQuality should be in range [3;5]"); | |
} | |
} | |
} | |
class SkiResortFacade // реализация паттерна "фасад" | |
{ | |
private SkiRent skiRent; | |
private SkiResortTicketSystem ticketSystem; | |
private HotelBookingSystem bookingSystem; | |
public SkiResortFacade() | |
{ | |
skiRent = new SkiRent(); | |
ticketSystem = new SkiResortTicketSystem(); | |
bookingSystem = new HotelBookingSystem(); | |
} | |
public double HaveAVeryVeryNiceTime(int height, int weight, int feetSize, int skierLevel, int roomQuality) | |
{ | |
double skiPrice = skiRent.RentSki(weight, skierLevel); | |
double skiBootsPrice = skiRent.RentBoots(feetSize, skierLevel); | |
double polesPrice = skiRent.RentSkiPoles(height); | |
double skiPassPrice = ticketSystem.BuySevenDaysTicket(); | |
double hotelPrice = bookingSystem.BookRoom(roomQuality); | |
return skiPrice + skiBootsPrice + polesPrice + skiPassPrice + hotelPrice; | |
} | |
public double HaveALittleFunWithYourOwnEquipmentAndTent() | |
{ | |
double skiPassPrice = ticketSystem.BuyOneDayTicket(); | |
return 0 + 0 + 0 + skiPassPrice + 0; | |
} | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
SkiResortFacade facade = new SkiResortFacade(); | |
double vacationPrice = facade.HaveAVeryVeryNiceTime(177, 80, 43, 0, 5); | |
// double vacationPrice = facade.HaveAVeryVeryNiceTime(177, 80, 43, 0, 4); | |
// double vacationPrice = facade.HaveAVeryVeryNiceTime(177, 80, 43, 0, 3); | |
// double vacationPrice = facade.HaveALittleFunWithYourOwnEquipmentAndTent(); | |
Console.WriteLine("Price: " + vacationPrice); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment