I have lately been reading on the Single Responsibility Principle
concept, and in theory I agree a lot with it. I am having difficulty coming to terms on which code can be exactly classified as violating the principle. I would like to implement this principle, so as to gear towards Test-Driven Development.
Take for example the code below:
public void MarkAsSuccessful(PaymentMethodSpecific paymentMethod, bool requiresManualIntervention)
{
this.Paid = true;
this.PaidOn = CS.General_v3.Util.Date.Now;
this.PaidByPaymentMethod = paymentMethod;
this.RequiresManualIntervention = requiresManualIntervention;
this.Update();
this.CreateAndSendNotificationRegardingImmediatePayment();
this.SendPaymentSuccessfulEmails();
}
This is placed in a class called PaymentRequest
, which basically is a class which handles logic related to payment in an e-commerce application. The method above marks the request as 'successful'. This must mark the columns paid, as well as other information, as well as send a notification that this was successful, and also send emails.
For example, when it comes to unit testing - It is very difficult to unit-test this method as I have no way to know that the notification was actually created and sent, as well as the payment emails have been sent. Would like to know how more experienced people on the SRP concept would approach such an example.