Skip to content

Instantly share code, notes, and snippets.

@SangSuantak
Last active February 19, 2022 08:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SangSuantak/35f16fc3cfdc38e0b0aa84d91fe12bdf to your computer and use it in GitHub Desktop.
Save SangSuantak/35f16fc3cfdc38e0b0aa84d91fe12bdf to your computer and use it in GitHub Desktop.
public interface IAPIProvider
{
void SearchHotels();
void GetHotelDetails();
void GetRoomDetails();
void GetCancellationPolicies();
void GetExtraGuestChargeDetails();
void BlockRoom();
void BookRoom();
void GetBookingDetails();
void CancelBooking();
}
public class ConcreteProviderA : IAPIProvider
{
public void BlockRoom()
{
//call api
}
public void BookRoom()
{
//call api
}
public void CancelBooking()
{
//call api
}
public void GetBookingDetails()
{
//call api
}
public void GetCancellationPolicies()
{
//call api
}
public void GetExtraGuestChargeDetails()
{
//call api
}
public void GetHotelDetails()
{
//call api
}
public void GetRoomDetails()
{
//call api
}
public void SearchHotels()
{
//call api
}
}
public class ConcreteProviderB : IAPIProvider
{
public void BlockRoom()
{
throw new NotImplementedException();
}
public void BookRoom()
{
//call api
}
public void CancelBooking()
{
//call api
}
public void GetBookingDetails()
{
//call api
}
public void GetCancellationPolicies()
{
throw new NotImplementedException();
}
public void GetExtraGuestChargeDetails()
{
throw new NotImplementedException();
}
public void GetHotelDetails()
{
//call api
}
public void GetRoomDetails()
{
//call api
}
public void SearchHotels()
{
//call api
}
}
/// <summary>
/// Request from web/mobile will land in this class
/// </summary>
public class Client
{
public void SearchHotel()
{
//get active providers from database & instantiate them
List<IAPIProvider> providers = new List<IAPIProvider>();
foreach(var provider in providers)
{
//search hotels from each API provider
provider.SearchHotels();
}
}
public void GetHotelDetails(int hotelId, int hotelProviderId)
{
IAPIProvider provider = null;
//here, resolve the correct API provider using the input parameters
//fetch hotel details from the resolved API provider
provider.GetHotelDetails();
}
//Other methods
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment