
I'm an enthusiastic Chilean software engineer in New Zeland. I mostly focus on the back-end of the systems. This is my site, Señor Developer, where I share my knowledge and experience.
Search for a command to run...

I'm an enthusiastic Chilean software engineer in New Zeland. I mostly focus on the back-end of the systems. This is my site, Señor Developer, where I share my knowledge and experience.
In this series, I will show you the S.O.L.I.D principle. They consist of five object-oriented design principles which guide developers in writing clean, maintainable and efficient code.
S.O.L.I.D principles series
Quilla Frontend Kit turns recurring API, authentication, and server-state concerns into composable TypeScript packages.

Quilla Backend Kit provides the foundations for structured TypeScript services while leaving the application architecture in your hands.

Practical constraints for preserving the framework’s boundaries, dependency direction, and readability as a test suite grows.

A tool-agnostic approach to separating test intent from UI mechanics as an automation suite grows.

In this article, we will go through the entire process of set up Visual Studio Code for debugging “Deno” programs using “V8 Inspector Protocol”. Step-by-step, we will be learning how to configure VSCode to debug a Deno project. If you don’t know Deno...

A class should only have one reason to change, or one responsibility, in accordance with the Single Responsibility Principle (SRP). This idea makes the code easier to comprehend and maintain by promoting a clear division of responsibilities.
One way to achieving the SRP is to divide various responsibilities into separate classes. By encapsulating a certain behaviour, this makes each class more cohesive and comprehensible.
For example, consider a class named "Musician" which is responsible for sing, play the guitar and play drums:

This violates the SRP because it has 3 distinct responsibilities: sing, play the guitar and play drums. Instead, we can create separate classes for each responsibility, such as a Singer class, Guitarist class and a Drummer class:

With the previous diagram, the responsibilities of sing, play the guitar and dance are separated into their own classes, following the SRP:
A guitarist is responsible for playing the guitar chords
The singer is responsible for sing the lyrics
And the drummer provide rhythm and beat to a performance
Similarly, in programming, classes should have clear and distinct responsibilities to avoid overlap and confusion. Let's see an implementation example:
class Singer {
public sing() {
console.log("Singing the lyrics");
}
}
class Guitarist {
public play() {
console.log("Playing the guitar");
}
}
class Drummer {
public play() {
console.log("Playing the drums");
}
}
// Creating instances of each musician
const singer = new Singer();
const guitarist = new Guitarist();
const drummer = new Drummer();
singer.sing();
guitarist.play();
drummer.play();
Single Responsibility Principle doesn’t mean do only one job, it means that everything it does should be closely related
See you in the next article of this series.