{"componentChunkName":"component---src-templates-blog-post-js","path":"/SOLID-Principles/","result":{"data":{"site":{"siteMetadata":{"title":"Ibrahim personal blog","author":"Ibrahim"}},"markdownRemark":{"id":"d4b9f4b3-76e8-5207-a479-3615ac04b8f6","html":"<p>As with everything in life, using these principles mindlessly\ncan cause more harm than good. The cost of applying these\nprinciples into a program’s architecture might be making it\nmore complicated than it should be. there’s no successful software product in which all of these principles are applied at once. Striving for these principles is good, but always try to be pragmatic and don’t take everything written here as dogma.</p>\n<p>These principles called the S.O.L.I.D principles is an acronym derived by Michael Feathers. S: Single Responsibility Principle O: Open-Closed Principle L: Liskov Substitution Principle I: Interface Segregation Principle D: Dependency Inversion Principle.\nSo let’s start with them briefly:</p>\n<p>1-<strong>Single Responsibility Principle</strong></p>\n<p>A class should have just one reason to change.\nTry to make every class responsible for a single part of\nthe functionality provided by the software.\nMake that responsibility entirely encapsulated.\nOne reason to change\nNotice The main goal of this principle is to reduce complexity.\nYou don’t need to invent a sophisticated design for a program that\nonly has about 200 lines of code. Make a dozen methods pretty,\nand you’ll be fine.\nThe real problems emerge when your program constantly grows and changes.</p>\n<p>2- <strong>Open/Closed Principle</strong></p>\n<p>Classes should be open for extension.\nBut at the same time close for modification.\nThe main idea of this principle is to keep existing\ncode from breaking when you implement new features.</p>\n<p>3- <strong>Liskov Substitution Principle</strong></p>\n<p>When extending a class, remember that you should be\nable to pass objects of the subclass in place of objects of\nthe parent class without breaking the client code.\nThis means that the subclass should remain compatible with the behavior of the superclass. When overriding a method,\nextend the base behavior rather than replacing it with something else entirely.</p>\n<p>This concept is critical when developing libraries and\nframeworks because your classes are going to be used\nby other people whose code you can’t directly access and change.</p>\n<p>Invariants are conditions in which an object makes sense.\nFor example, invariants of a cat are having\nfour legs, a tail, the ability to meow, etc.</p>\n<p>4- <strong>Interface Segregation Principle</strong> (ISP)</p>\n<p>Clients shouldn’t be forced to depend on methods they do not use.\nISP 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. Such shrunken interfaces are also called role interfaces.\nAnd notice Correct abstraction is the key to Interface Segregation Principle.</p>\n<p>5- <strong>Dependency Inversion Principle</strong> (DIP)</p>\n<p>High-level classes shouldn’t depend on low-level classes.\nBoth should depend on abstractions. Abstractions shouldn’t depend on details. Details should depend on\nabstractions.</p>\n<p>To make a distinction between low and high-level classes\n• Low-level classes implement basic operations such as working\nwith a disk, transferring data over a network, connecting to a\ndatabase, etc.\n• High-level classes contain complex business logic that directs\nlow-level classes to do something.</p>\n<p>In quick words how to implement DIP\nA-Build low-level classes\nB-Build its interface based on abstraction\nC-Build high-level classes</p>\n<p><strong>Conclusion</strong></p>\n<p>We discussed briefly the solid principles when designing software,\nalthough you would never implement them each project you wok with,\nIn the other hand; it is good to put those principles on notice when\ncoding or when design the software by the architect.</p>","timeToRead":2,"frontmatter":{"title":"The \"SOLID\" Principles in designing software","date":"August 12, 2019","spoiler":"brief introduction to the SOLID principles in programming","tags":"SOLID JS Priciplal_Learning Coding"},"fields":{"slug":"/SOLID-Principles/","langKey":"en"}}},"pageContext":{"slug":"/SOLID-Principles/","previous":{"fields":{"slug":"/Depedency-Inversion/","langKey":"en","directoryName":"Depedency-Inversion","maybeAbsoluteLinks":[]},"frontmatter":{"title":"What is depedency inversion"}},"next":{"fields":{"slug":"/Functional/","langKey":"en","directoryName":"Functional","maybeAbsoluteLinks":[]},"frontmatter":{"title":"Functional programming"}},"translations":[],"translatedLinks":[]}}}