Posts

Showing posts from December, 2022

SOLID Principles

  SOLID Principles S - Single Responsibility Principle A class is responsible only for a single task Suppose we need to process a order where set of task need to be done like validate order, save order and send notification to the customer. Bad Practice: public class OrderProcessor {     //define the subtask to process order     public void ValidateOrder() { //definition goes here}     p ublic void SaveOrder() { //definition goes here }     p ublic void SendNotification() { //definition goes here }     public void Process()     {          ValidateOrder();          SaveOrder();          SendNotification();     } } The above example violates the single responsibility principle. Because a single class take all the responsibility to process order. Good Practice: public class OrderProcessor ...