S.O.L.I.D

S — Single responsibility principle

  1. Testing — A class with one responsibility will have far fewer test cases
  2. Lower coupling — Less functionality in a single class will have fewer dependencies
  3. Organisation — Smaller, well-organised classes are easier to search than monolithic ones
class Person {
constructor(name: string){ }
getPersonName() { }
savePerson(a: Person) { }
}
class Person {
constructor(name: string){ }
getPersonName() { }
}
class PersonFromDB {
getPerson(a: Person) { }
savePerson(a: Person) { }
}

O — Open/closed principle

  • Open for extension
  • Closed for modification
class Offer {
giveOffer() {
return this.price * 0.2
}
}
class Offer {
giveOffer() {
if(this.customer == 'loyal') {
return this.price * 0.2;
}
if(this.customer == 'returning') {
return this.price * 0.4;
}
}
}
class ReturningOffer: Offer {
getOffer() {
return super.getOffer() * 2;
}
}

L — Liskov substitution principle

I — Interface segregation principle

D — Dependency inversion principle

  1. High-level modules should not depend on low-level modules. Both should depend on abstractions.
  2. Abstractions should not depend on details. Details should depend on abstractions.
  1. the high-level module depends on the abstraction, and
  2. the low-level depends on the same abstraction.

More Resources:

--

--

--

https://github.com/byronskout

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Azure DevOps Pipeline Complete Guide

The Future of Data Science and Parallel Computing

Step by Step : Install Android Studio, Visual Code & Flutter in Ubuntu

Introduction to OOPS in C++

Dive Bomb Enemies!

A real Kafka tutorial with replication & fault tolerence

Multi-Containers App on AWS Fargate

Unrecoverable EdTech Error

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Byron Skoutaris

Byron Skoutaris

https://github.com/byronskout

More from Medium

CREATING STRING VARIABLE

Kotlin Cheatsheet 9 — Companion Object

Fifteen minutes to create an application interface with iofod