Last active
January 24, 2021 16:02
-
-
Save ThiagoBarradas/6595c45ebd06cfebaa630775bd76dca5 to your computer and use it in GitHub Desktop.
SOLID [L] - Wrong Method
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
public abstract class Transaction | |
{ | |
public long OriginalAmount { get; set; } | |
} | |
public class CreditCardTransaction : Transaction | |
{ | |
public long InterestAmount { get; set; } | |
} | |
public class PixTransaction : Transaction | |
{ | |
} | |
// class that needs transaction | |
public class Order | |
{ | |
// ctor and some properties | |
public long TotalPaid { get; private set; } | |
// wrong method | |
public void AddTransaction(Transaction transaction) | |
{ | |
var totalPaid = transaction.OriginalAmount; | |
if (transaction is CreditCardTransaction) | |
{ | |
totalPaid += ((CreditCardTransaction)transaction).InterestAmount; | |
} | |
this.TotalPaid += totalPaid; | |
// do something more | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment