Angular

Last Updated: 9/4/2023

Separation of concerns

  • Our classes should have a single responsibility
  • Eg In restaurant we have many roles chef, waiter, manager. Chef is responsible for only 1 thing cooking, he will not come and take order
  • A class that does too many things violates separation of concern principle, such a class is hard to maintain and test
  • A Component must include only the presentation logic behind the view not the logic to get and save data.

Problem

  • If the component is getting and saving data directly.
  • It needs to know the endpoint, work with http class, construct the URL in update and delete method
  • Duplication of logic if another component also requires to get and save same type of data
  • Harder to test.
  • In Unit Test we don't want to have live server up and running - Don't want to make http calls to the server - If server is not running our unit test will fail - Http calls will slow down automated test
  • Never call http services in automated test