Skip to content

Instantly share code, notes, and snippets.

@ThiagoBarradas
Last active January 24, 2021 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThiagoBarradas/6595c45ebd06cfebaa630775bd76dca5 to your computer and use it in GitHub Desktop.
Save ThiagoBarradas/6595c45ebd06cfebaa630775bd76dca5 to your computer and use it in GitHub Desktop.
SOLID [L] - Wrong Method
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