Last active
January 14, 2021 19:50
-
-
Save ThiagoBarradas/b5cfc9f01ee16305e5dd9ff25d101218 to your computer and use it in GitHub Desktop.
SOLID [S] - Extracting Method (Method with SRP) but with wrong class structure
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 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