Open-closed in Angular heading

SOLID: The First 5 Principles of Object-Oriented Design

In software development, we encounter numerous scenarios where our codebase is not scalable enough. That kind of behaviour could cause problems in future that will be very difficult to maintain. 

The SOLID idea gives you a set of 5 rules that are: 

  • The Single-Responsibility principle (SRP)
  • The Open-closed principle
  • The Liskow Substitution principle (LSP)
  • The Interface Segregation principle (ISP)
  • The Dependency Injection principle (DIP)

Open-closed principle in Angular

This principle states that software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. In other words, we should be able to add new functionality without modifying existing code.

OCP can be applied using inheritance and interfaces. For example, we can create a base component or service that contains common functionality and then create child components or services that inherit from the base component or service. We can also create interfaces for components or services that define a set of methods or properties that must be implemented.

Before we start

Lest make changes to the application itseft and convert it to the standalone application.

First we need to modify our AppComponent and convert it standalone component.

In component decorator of our AppComponent, we will add imports declaration and import RouterModule.