single responsibility principle

This principle is quite simple: a class should have one, and only one purpose in your application. Use a Person object only to store data about a person (name, age, address..) but you may not use it to format how the date is displayed. Use a DownloadHelper to download a file but not to process its content.

Why is this desirable?

  • extensibility & maintainability
  • It avoids code duplication
  • It forces the developer to break down his application into smaller, easier manageable parts

As an example, if you as a developer new to a large project have the task to change the formatting of the date, you would not need to know which objects display dates, you only have to find and adapt a class with a name similar to FormatHelper or DateTimeFormater.

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *