Last active
March 24, 2020 14:28
-
-
Save MufidJamaluddin/1fd20f297d2d9a1c4a27294a4ed00c07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public abstract class Invoice | |
| { | |
| protected Motorcycle Motor {get;} | |
| protected Duration TrackDuration {get;} | |
| public Invoice(Motorcycle motor, Duration duration) | |
| { | |
| this.Motor = motor; | |
| this.TrackDuration = duration; | |
| } | |
| public abstract Double CalculateInvoice(); | |
| public virtual void PayInvoice() | |
| { | |
| // bayar tagihan | |
| } | |
| } | |
| public class RentInvoice : Invoice | |
| { | |
| public RentInvoice(Motorcycle motor, Duration duration) : base(Motorcycle motor, Duration duration) | |
| { | |
| } | |
| public override Double CalculateInvoice() | |
| { | |
| // perhitungan tagihan tracking motor sewaan | |
| } | |
| public override void PayInvoice() | |
| { | |
| // pembayaran struk tracking khusus motor sewaan | |
| } | |
| } | |
| public class LoanInvoice : Invoice | |
| { | |
| public LoanInvoice(Motorcycle motor, Duration duration) : base(Motorcycle motor, Duration duration) | |
| { | |
| } | |
| public override Double CalculateInvoice() | |
| { | |
| // perhitungan tagihan tracking motor pinjaman | |
| } | |
| } | |
| public class PersonalInvoice : Invoice | |
| { | |
| public PersonalInvoice(Motorcycle motor, Duration duration) : base(Motorcycle motor, Duration duration) | |
| { | |
| } | |
| public override Double CalculateInvoice() | |
| { | |
| // perhitungan tagihan tracking motor personal | |
| } | |
| } | |
| 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), | |
| _ => 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