Skip to main content

Posts

Showing posts from July, 2021

Single Responsability Principle

The Single Responsibility Principle states that a class should have only a single responsibility. A class can do a simple job or a complex job, but if it's designed to carry many responsibilities it can increase the possibility of bugs.  This principle is focused on separating behaviors so that if a bug comes up it won't affect other unrelated behaviors. Suppose that you are building a class CustomerSearch as shown below. public class CustomerSearch {          private ArrayList<Customer> customers = new ArrayList<>();     public CustomerSearch() {         this.customers.add(new Customer("Great Lake","USA","NYC"));         this.customers.add(new Customer("The Dog","USA","Chicago"));         this.customers.add(new Customer("The Jam","USA","Seattle"));         this.customers.add(new Customer("The Box","Japan","Tokyo"));     }      ...