Skip to content

Instantly share code, notes, and snippets.

@MufidJamaluddin
Created March 24, 2020 14:20
Show Gist options
  • Save MufidJamaluddin/7736242b9d9f36ec5688b89c49558694 to your computer and use it in GitHub Desktop.
Save MufidJamaluddin/7736242b9d9f36ec5688b89c49558694 to your computer and use it in GitHub Desktop.
public class MogeInvoice : Invoice
{
public MogeInvoice(Motorcycle motor, Duration duration) : base(Motorcycle motor, Duration duration)
{
}
public override Double CalculateInvoice()
{
// perhitungan invoice Moge
}
}
public static class InvoiceFactory
{
public static Invoice Create(Motorcycle motor, Duration duration)
{
return motor.type switch {
"rent" => return new RentInvoice(motor, duration),
"loan" => return new LoanInvoice(motor, duration),
"personal" => return new PersonalInvoice(motor, duration),
// tambah disini!
"moge" => return new MogeInvoice(motor, duration),
_ => throw new Exception("Motorcycle type is invalid!"),
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment