Last active
June 8, 2023 21:10
-
-
Save ThiagoBarradas/4320c94be66895eda91cc2bbd0f830e6 to your computer and use it in GitHub Desktop.
SOLID [S] - Splitting class (Class with SRP)
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 : IPaymentService | |
{ | |
private readonly IPaymentRepository PaymentRepository; | |
private readonly INotificationService NotificationService; | |
private readonly IBankService BankService; | |
public PaymentService( | |
IPaymentRepository paymentRepository, | |
INotificationService notificationService, | |
IBankService bankService) | |
{ | |
this.PaymentRepository = paymentRepository; | |
this.NotificationService = notificationService; | |
this.BankService = bankService; | |
} | |
public Payment ProcessPayment(Payment payment) | |
{ | |
var transaction = this.BankService.CreateTransaction(payment); | |
payment.AddBankTransaction(transaction); | |
var notificationMessage = payment.Map<NotificationMessage>(); | |
this.NotificationService.NotifyByEmail(notificationMessage) | |
this.PaymentRepository.CreatePayment(payment); | |
return payment; | |
} | |
} | |
public class PaymentRepository : BaseRepository<Payment>, IPaymentRepository | |
{ | |
// contructor / dependencies | |
public void CreatePayment(Payment payment) | |
{ | |
// code code code | |
} | |
} | |
public class NotificationService : INotificationService | |
{ | |
// contructor / dependencies | |
public void NotifyByEmail(NotificationMessage notificationMessage) | |
{ | |
// code code code | |
} | |
} | |
public class NotificationMessage | |
{ | |
// data transfer obejct | |
} | |
public class BankService : IBankService | |
{ | |
// contructor / dependencies | |
public Transaction CreateTransaction(Payment payment) | |
{ | |
// code code code | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment