Created
January 24, 2021 16:05
-
-
Save ThiagoBarradas/b9d40f81862dad34e477eaab35aaca5a to your computer and use it in GitHub Desktop.
SOLID [L] Wrong Abstraction
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 class Transaction | |
{ | |
public virtual long OriginalAmount { get; set; } | |
public virtual long InterestAmount { get; set; } | |
} | |
public class CreditCardTransaction : Transaction | |
{ | |
} | |
public class PixTransaction : Transaction | |
{ | |
public override long InterestAmount | |
{ | |
get { throw new InvalidOperationException(); } | |
set { throw new InvalidOperationException(); } | |
} | |
} | |
// class that needs transaction | |
public class Order | |
{ | |
// ctor and some properties | |
public long TotalPaid { get; private set; } | |
public void AddTransaction(Transaction transaction) | |
{ | |
this.TotalPaid += transaction.OriginalAmount; | |
this.TotalPaid += transaction.InterestAmount; | |
// do something more | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment