Created
May 27, 2024 08:13
-
-
Save sunmeat/912455b265cbcbd62971f5a5c53f1642 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
// https://bukovel.com/ru/ski/hire | |
class SkiRent // аренда снаряжения | |
{ | |
public double RentBoots(int feetSize, int skierLevel) // ботинки | |
{ | |
double price = 259.99; | |
// if (feetSize < 35) price -= 20; // скидка для детей | |
return price; | |
} | |
public double RentHelmet(int headSize, int skierLevel) // шлем | |
{ | |
return 220; | |
} | |
public double RentSki(int weight, int skierLevel) // лыжи | |
{ | |
return 280; | |
} | |
public double RentSkiPoles(int height) // лыжные палки | |
{ | |
return 150; | |
} | |
} | |
// 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 TravelCompany // реализация паттерна "фасад" | |
{ | |
private SkiRent sr = new SkiRent(); | |
private SkiResortTicketSystem ts = new SkiResortTicketSystem(); | |
private HotelBookingSystem hb = new HotelBookingSystem(); | |
public double HaveAVeryVeryNiceTime(int height, int weight, int feetSize, int skierLevel, int roomQuality) | |
{ | |
double skiPrice = sr.RentSki(weight, skierLevel); | |
double skiBootsPrice = sr.RentBoots(feetSize, skierLevel); | |
double polesPrice = sr.RentSkiPoles(height); | |
double skiPassPrice = ts.BuySevenDaysTicket(); | |
double hotelPrice = hb.BookRoom(roomQuality); | |
return skiPrice + skiBootsPrice + polesPrice + skiPassPrice + hotelPrice; | |
} | |
public double HaveALittleFunWithYourOwnEquipmentAndTent() | |
{ | |
double skiPassPrice = ts.BuyOneDayTicket(); | |
return skiPassPrice; | |
} | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
TravelCompany facade = new TravelCompany(); | |
float vacationPrice = (float)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