Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ThiagoBarradas
Last active June 8, 2023 21:10
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/4320c94be66895eda91cc2bbd0f830e6 to your computer and use it in GitHub Desktop.
Save ThiagoBarradas/4320c94be66895eda91cc2bbd0f830e6 to your computer and use it in GitHub Desktop.
SOLID [S] - Splitting class (Class with SRP)
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