Skip to content

Instantly share code, notes, and snippets.

@ThiagoBarradas
Last active January 14, 2021 19:50
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/b5cfc9f01ee16305e5dd9ff25d101218 to your computer and use it in GitHub Desktop.
Save ThiagoBarradas/b5cfc9f01ee16305e5dd9ff25d101218 to your computer and use it in GitHub Desktop.
SOLID [S] - Extracting Method (Method with SRP) but with wrong class structure
public class PaymentService
{
// ctors
// properties
// etc
public Payment ProcessPayment(Payment payment)
{
var transaction = this.BankService.CreateTransaction(payment);
payment.AddBankTransaction(transaction);
this.NotifyPayment(payment)
this.SavePayment(payment);
return payment;
}
public void NotifyPayment(Payment payment)
{
var mail = new MailMessage();
mail.From = new MailAddress(payment.Merchant.Email);
mail.To.Add(payment.Customer.Email);
mail.Subject = "Bla bla bla";
mail.Body = "bla bla bla";
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.Send(mail);
// code code code
}
public void SavePayment(Payment payment)
{
using (var sqlConnection = new SqlConnection(this.DatabaseConfiguration.ConnectionString))
{
var query = "INSERT INTO Payments (...)";
var result = sqlConnection.ExecuteReader(query, payment);
// code code code
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment