SlideShare a Scribd company logo
@jonathanfmills
Jonathan Mills
SOLID JavaScript
What’s the Problem?
Solid js
Solid js
What is SOLID?
Five design principles intended to make software designs
more understandable, flexible and maintainable.
SOLID
Single responsibility principle
Open/closed principle
Liskov substitution principle
Interface segregation principle
Dependency inversion principle
“SOLID principles are a means of
forcing us to stop and think about the
‘right’ way to do something.”
-Me
Disclaimer!
Single Responsibility
Solid js
Every module or class should have responsibility over a single
part of the functionality provided by the software, and that
responsibility should be entirely encapsulated by the class.
All its services should be narrowly aligned with that
responsibility.
Single Responsibility Principle
“A class should have a single reason
to change”
Robert C Martin
Open Closed Principle
Solid js
Open / Closed Principle
Software entities (classes, modules, functions, etc.) should be
open for extension, but closed for modification
We can do this in JavaScript?
Inheritance
var Task = function (name) {
this.name = name;
this.completed = false;
}
Task.prototype.complete = function () {
console.log('completing task: ' + this.name);
this.completed = true;
};
Task.prototype.save = function () {
console.log('saving Task: ' + this.name);
};
var myTask = new Task('Legacy Task');
myTask.complete();
myTask.save();
I need this urgently!!!
var urgentTask = new Task('Urgent Task');
urgentTask.priority = 2;
urgentTask.notify = function(){
console.log('notifying important people');
};
urgentTask.complete();
urgentTask.save = function(){
this.notify();
Task.prototype.save.call(this)
};
urgentTask.save();
That’s only half way…
var UrgentTask = function (name, priority) {
Task.call(this, name);
this.priority = priority;
};
UrgentTask.prototype = Object.create(Task.prototype);
UrgentTask.prototype.notify = function () {
console.log('notifying important people');
};
UrgentTask.prototype.save = function () {
this.notify();
console.log('do special stuff before saving');
Task.prototype.save.call(this)
};
var ut = new UrgentTask('This is urgent', 1);
ut.complete();
ut.save();
Open / Closed Principle
Software entities (classes, modules, functions, etc.) should be
open for extension, but closed for modification
Liskov Substitution
Who is Liskov?
What is she trying to
substitute?
Barbara Liskov
American computer scientist who is an Institute Professor at the Massachusetts
Institute of Technology and Ford Professor of Engineering in its School of
Engineering's electrical engineering and computer science department.
She was one of the first women to be granted a doctorate in computer science in
the United States and is a Turing Award winner who developed the Liskov
substitution principle.
Let q(x) be a property provable about objects of x of
type T. Then q(y) should be provable for objects y of
type S where S is a subtype of T.
Liskov Substitution
Solid js
Solid js
Every subclass/derived class should be substitutable for
their base/parent class.
Liskov Substitution
Solid js
Solid js
What makes a rectangle?
What makes a square?
What happens when I
substitute a rectangle for a
square?
var Task = function (name) {
this.name = name;
this.completed = false;
}
var myTask = new Task('Legacy Task'); //Can I substitute
//Urgent task here?
myTask.complete();
myTask.save();
Interface Segregation
Solid js
Interface Segregation
No client should be forced to depend on methods it does not
use. ISP splits interfaces that are very large into smaller and
more specific ones so that clients will only have to know
about the methods that are of interest to them.
“Keep your interfaces simple”
The ISP was first used and formulated by Robert C.
Martin when doing some consulting for Xerox.
ISP
Xerox had created a new printer system that could perform a
variety of tasks like stapling a set of printed papers and
faxing. The software for this system was created from the
ground up and performed its tasks successfully.
ISP
As the software grew, making modification became more
and more difficult so that even the smallest change would
take a redeployment cycle to an hour. This was making it
near impossible to continue development.
ISP
The design problem was that one main Job class was used by
almost all of the tasks. Anytime a print job or a stapling job
had to be done, a call was made to some method in the Job
class. This resulted in a huge or 'fat' class with multitudes of
methods specific to a variety of different clients.
ISP
Because of this design, a staple job would know about all
the methods of the print job, even though there was no
use for them.
ISP
How do we solve this?
The solution suggested by Martin is what is called the
Interface Segregation Principle today.
Solution
Applied to the Xerox software, a layer of interfaces
between the Job class and all of its clients was added
using the Dependency Inversion Principle.
Solution
Instead of having one large Job class, a Staple Job
interface or a Print Job interface was created that would
be used by the Staple or Print classes, respectively,
calling methods of the Job class.
Solution
Therefore, one interface was created for each job, which
were all implemented by the Job class.
Solution
A facade is an object that provides a simplified interface
to a larger body of code
Façade Pattern
Dependency Inversion Principle
Solid js
Dependency Inversion
A. High-level modules should not depend on low-level modules.
Both should depend on abstractions.
B. Abstractions should not depend on details. Details should
depend on abstractions.
Dependency Inversion
A. High-level modules should not depend on low-level modules.
Both should depend on abstractions.
B. Abstractions should not depend on details. Details should
depend on abstractions.
So now what?
Solid js

More Related Content

PPTX
Solid principles
Monica Rodrigues
 
PDF
Solid.js - następca Reacta?
Brainhub
 
PPTX
Agile Mindset Shifting: Agile For All
India Scrum Enthusiasts Community
 
PDF
Clean Code
Daniel Kummer
 
PDF
2 ModéLe Mvc
Dghaies Jihed , PSM I Ⓡ
 
PPTX
Microfrontends Monoreops & Trunkbased based
Vinci Rufus
 
PDF
Solid principles
Kumaresh Chandra Baruri
 
PPTX
Solid principles
Viet Vu
 
Solid principles
Monica Rodrigues
 
Solid.js - następca Reacta?
Brainhub
 
Agile Mindset Shifting: Agile For All
India Scrum Enthusiasts Community
 
Clean Code
Daniel Kummer
 
Microfrontends Monoreops & Trunkbased based
Vinci Rufus
 
Solid principles
Kumaresh Chandra Baruri
 
Solid principles
Viet Vu
 

Similar to Solid js (20)

PPTX
The good, the bad and the SOLID
Frikkie van Biljon
 
PPTX
SOLID Principles
akbarashaikh
 
PDF
L22 Design Principles
Ólafur Andri Ragnarsson
 
PPTX
Becoming a better developer by using the SOLID design principles
Katerina Trajchevska
 
KEY
SOLID Design Principles
Samuel Breed
 
PPT
design-principles.ppt
WalidLahsiki
 
PDF
EKON28 - Beyond Legacy Apps with mORMot 2
Arnaud Bouchez
 
PPTX
SOLID Principles in OOPS ooooooooo.pptx
banjaaring
 
PPTX
Soild principles
Avidnyat Chiddarwar
 
PPTX
Learning solid principles using c#
Aditya Kumar Rajan
 
PPT
DesignPrinciples-and-DesignPatterns
Basavaraj Patil
 
PPTX
Object Oriented Principle’s
vivek p s
 
PPTX
Solid
Romexsoft
 
PPT
principles of object oriented class design
Neetu Mishra
 
PDF
SOLID Design Principles for Test Automaion
Knoldus Inc.
 
PPTX
An ultimate guide to SOLID Principles, developers must know.
ONE BCG
 
PDF
2024 DAPUG Conference Arnaud Bouchez From Classes to Interfaces
Arnaud Bouchez
 
PPTX
From Good to SOLID: How to become a better PHP developer
Katerina Trajchevska
 
PDF
SOLID Design principles
Mohamed Sanaulla
 
PPTX
GDSC - SOLID Principles session.pptx
AaliyanShaikh
 
The good, the bad and the SOLID
Frikkie van Biljon
 
SOLID Principles
akbarashaikh
 
L22 Design Principles
Ólafur Andri Ragnarsson
 
Becoming a better developer by using the SOLID design principles
Katerina Trajchevska
 
SOLID Design Principles
Samuel Breed
 
design-principles.ppt
WalidLahsiki
 
EKON28 - Beyond Legacy Apps with mORMot 2
Arnaud Bouchez
 
SOLID Principles in OOPS ooooooooo.pptx
banjaaring
 
Soild principles
Avidnyat Chiddarwar
 
Learning solid principles using c#
Aditya Kumar Rajan
 
DesignPrinciples-and-DesignPatterns
Basavaraj Patil
 
Object Oriented Principle’s
vivek p s
 
Solid
Romexsoft
 
principles of object oriented class design
Neetu Mishra
 
SOLID Design Principles for Test Automaion
Knoldus Inc.
 
An ultimate guide to SOLID Principles, developers must know.
ONE BCG
 
2024 DAPUG Conference Arnaud Bouchez From Classes to Interfaces
Arnaud Bouchez
 
From Good to SOLID: How to become a better PHP developer
Katerina Trajchevska
 
SOLID Design principles
Mohamed Sanaulla
 
GDSC - SOLID Principles session.pptx
AaliyanShaikh
 
Ad

Recently uploaded (20)

PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Doc9.....................................
SofiaCollazos
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Ad

Solid js

  • 6. Five design principles intended to make software designs more understandable, flexible and maintainable. SOLID
  • 7. Single responsibility principle Open/closed principle Liskov substitution principle Interface segregation principle Dependency inversion principle
  • 8. “SOLID principles are a means of forcing us to stop and think about the ‘right’ way to do something.” -Me
  • 12. Every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. Single Responsibility Principle
  • 13. “A class should have a single reason to change” Robert C Martin
  • 16. Open / Closed Principle Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification
  • 17. We can do this in JavaScript? Inheritance
  • 18. var Task = function (name) { this.name = name; this.completed = false; }
  • 19. Task.prototype.complete = function () { console.log('completing task: ' + this.name); this.completed = true; }; Task.prototype.save = function () { console.log('saving Task: ' + this.name); };
  • 20. var myTask = new Task('Legacy Task'); myTask.complete(); myTask.save();
  • 21. I need this urgently!!!
  • 22. var urgentTask = new Task('Urgent Task'); urgentTask.priority = 2; urgentTask.notify = function(){ console.log('notifying important people'); }; urgentTask.complete();
  • 25. var UrgentTask = function (name, priority) { Task.call(this, name); this.priority = priority; }; UrgentTask.prototype = Object.create(Task.prototype);
  • 26. UrgentTask.prototype.notify = function () { console.log('notifying important people'); }; UrgentTask.prototype.save = function () { this.notify(); console.log('do special stuff before saving'); Task.prototype.save.call(this) };
  • 27. var ut = new UrgentTask('This is urgent', 1); ut.complete(); ut.save();
  • 28. Open / Closed Principle Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification
  • 30. Who is Liskov? What is she trying to substitute?
  • 31. Barbara Liskov American computer scientist who is an Institute Professor at the Massachusetts Institute of Technology and Ford Professor of Engineering in its School of Engineering's electrical engineering and computer science department. She was one of the first women to be granted a doctorate in computer science in the United States and is a Turing Award winner who developed the Liskov substitution principle.
  • 32. Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T. Liskov Substitution
  • 35. Every subclass/derived class should be substitutable for their base/parent class. Liskov Substitution
  • 38. What makes a rectangle?
  • 39. What makes a square?
  • 40. What happens when I substitute a rectangle for a square?
  • 41. var Task = function (name) { this.name = name; this.completed = false; }
  • 42. var myTask = new Task('Legacy Task'); //Can I substitute //Urgent task here? myTask.complete(); myTask.save();
  • 45. Interface Segregation No client should be forced to depend on methods it does not use. ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them.
  • 47. The ISP was first used and formulated by Robert C. Martin when doing some consulting for Xerox. ISP
  • 48. Xerox had created a new printer system that could perform a variety of tasks like stapling a set of printed papers and faxing. The software for this system was created from the ground up and performed its tasks successfully. ISP
  • 49. As the software grew, making modification became more and more difficult so that even the smallest change would take a redeployment cycle to an hour. This was making it near impossible to continue development. ISP
  • 50. The design problem was that one main Job class was used by almost all of the tasks. Anytime a print job or a stapling job had to be done, a call was made to some method in the Job class. This resulted in a huge or 'fat' class with multitudes of methods specific to a variety of different clients. ISP
  • 51. Because of this design, a staple job would know about all the methods of the print job, even though there was no use for them. ISP
  • 52. How do we solve this?
  • 53. The solution suggested by Martin is what is called the Interface Segregation Principle today. Solution
  • 54. Applied to the Xerox software, a layer of interfaces between the Job class and all of its clients was added using the Dependency Inversion Principle. Solution
  • 55. Instead of having one large Job class, a Staple Job interface or a Print Job interface was created that would be used by the Staple or Print classes, respectively, calling methods of the Job class. Solution
  • 56. Therefore, one interface was created for each job, which were all implemented by the Job class. Solution
  • 57. A facade is an object that provides a simplified interface to a larger body of code Façade Pattern
  • 60. Dependency Inversion A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend on details. Details should depend on abstractions.
  • 61. Dependency Inversion A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend on details. Details should depend on abstractions.