[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"content:legacy:page:\u002Fposts\u002Ftutorial\u002Fwhat-is-solid":3,"content:legacy:navigation":257,"content:legacy:surround:\u002Fposts\u002Ftutorial\u002Fwhat-is-solid":542,"content:related-articles:Better code with SOLID principles":545},{"id":4,"title":5,"aside":6,"body":7,"categories":6,"category":240,"description":241,"duration":242,"extension":243,"footer":6,"header":6,"icon":6,"image":244,"main":6,"meta":247,"navigation":6,"path":248,"publishedAt":249,"seo":250,"sitemap":251,"stem":252,"tags":253,"toc":6,"top":255,"__hash__":256},"content\u002Fposts\u002Ftutorial\u002Fwhat-is-solid.md","Better code with SOLID principles",null,{"type":8,"value":9,"toc":233},"minimark",[10,15,19,57,60,64,67,72,87,91,109,113,128,132,144,148,166,170,173,176,180],[11,12,14],"h2",{"id":13},"revise-oop-concepts","📚 Revise OOP concepts",[16,17,18],"p",{},"Object-oriented programming (OOP) is one of the most widely used programming paradigms. The special properties that make object-oriented programming effective are:",[20,21,22,33,41,49],"ul",{},[23,24,25,32],"li",{},[26,27,28],"strong",{},[29,30,31],"code",{},"Abstraction",": Creating abstract classes to model objects in the real world.",[23,34,35,40],{},[26,36,37],{},[29,38,39],{},"Encapsulation",": The entities of an abstract class have distinct attribute values.",[23,42,43,48],{},[26,44,45],{},[29,46,47],{},"Inheritance",": Objects can easily inherit and extend each other.",[23,50,51,56],{},[26,52,53],{},[29,54,55],{},"Polymorphism",": An action can be performed in many different ways depending on the specific type of object being called.",[16,58,59],{},"These special properties of OOP help us build programs that solve many different specific problems in the real world. Most programmers are already familiar with these properties of OOP, but not everyone knows how to combine these properties to increase the efficiency of the application. One of the guidelines to help us use OOP more effectively is the SOLID principles.",[11,61,63],{"id":62},"what-is-solid","🧱 What is SOLID?",[16,65,66],{},"SOLID is an acronym for the first five principles of object-oriented design. It helps programmers write code that is easy to read, understand, and maintain. It was introduced by Robert C. Martin and Michael Feathers. These five principles include:",[68,69,71],"h5",{"id":70},"_1-single-responsibility-principle-srp","1. Single responsibility principle (SRP)",[73,74,75],"card",{},[76,77,79],"template",{"v-slot:content":78},"",[20,80,81,84],{},[23,82,83],{},"Simply put, each component should only perform and be responsible for a certain part of the work.",[23,85,86],{},"For example, in the MVC model: there will be components such as SERVICE, REPOSITORY, CONTROLLERS. Each component should only take on a certain task such as service related to data processing, repository helps manipulate the database, controller helps process and navigate requests from client to server, ...",[68,88,90],{"id":89},"_2-openclosed-principle-ocp","2. Open\u002FClosed principle (OCP)",[73,92,93],{},[76,94,95],{"v-slot:content":78},[20,96,97,100,103,106],{},[23,98,99],{},"Open for extension closed for modification",[23,101,102],{},"Do not modify an existing Class, but can extend it by inheritance.",[23,104,105],{},"According to this principle, whenever we want to add a function to the program, we should write a new class that extends the old class (by inheriting or owning the old class) and not modify the old class. This leads to the emergence of many classes, but we will not need to test the old classes again, but only focus on testing the new classes, which contain the new functions.",[23,107,108],{},"Normally, expanding the function requires writing more code, so what do we need to do to design a module that can be easily extended but limits code modification? The solution is to separate the parts that are easy to change from the parts that are difficult to change while ensuring that the remaining parts are not affected.",[68,110,112],{"id":111},"_3-liskov-substitution-principle-lsp","3. Liskov substitution principle (LSP)",[73,114,115],{},[76,116,117],{"v-slot:content":78},[20,118,119,122,125],{},[23,120,121],{},"Objects (instances) of a child class can replace objects of a parent class without causing errors.",[23,123,124],{},"The importance of this principle becomes clear when you see the consequences of violating it. Suppose we have a function f of a base class B. Suppose we have a class D that is derived from B and when we call function f on an object of D in the same way as we do on B, f behaves incorrectly. D then violates the LSP. Clearly, D becomes fragile in the presence of f.",[23,126,127],{},"The author of f will try to add some details to make it testable with D so that f can behave correctly when called from an object of D. This will violate OCP because f is not completely closed to all classes derived from B. The code smells and it is clearly the result of an inexperienced programmer (or, worse, a hasty programmer) trying to resolve the LSP conflict.",[68,129,131],{"id":130},"_4-interface-segregation-principle-isp","4. Interface segregation principle (ISP)",[73,133,134],{},[76,135,136],{"v-slot:content":78},[20,137,138,141],{},[23,139,140],{},"Instead of using a large interface, we should separate it into many small interfaces, with many specific purposes.",[23,142,143],{},"This principle is very easy to understand. Imagine we have a large interface, about 100 methods. Implementation will be very difficult because the classes that implement this interface will be required to implement all the methods of the interface. In addition, it can be redundant because a class does not need to use all 100 methods. When separating the interface into many small interfaces, including related methods, implementation and management will be easier.",[68,145,147],{"id":146},"_5-dependency-inversion-principle-dip","5. Dependency inversion principle (DIP)",[73,149,150],{},[76,151,152],{"v-slot:content":78},[20,153,154,157,160,163],{},[23,155,156],{},"High-level modules should not depend on low-level modules. Both should depend on abstraction.",[23,158,159],{},"Interface (abstraction) should not depend on details, but vice versa (Classes communicate with each other through interface (abstraction), not through implementation.)",[23,161,162],{},"This principle can be understood as follows: components in a program should only depend on abstractions. Abstract components should not depend on concrete components, but vice versa.",[23,164,165],{},"Abstractions are those that change and fluctuate little, they gather the most common characteristics of concrete ones. Concrete ones, no matter how different, follow the general rules that abstractions have defined. Dependence on abstractions will help the program be flexible and adapt well to continuous changes.",[11,167,169],{"id":168},"example","💡 Example",[16,171,172],{},"For example, with a computer hard drive, you can use a new generation SSD solid-state drive to run faster, but you can also use a regular HDD spinning drive. The motherboard manufacturer has no way of knowing whether you will use an SSD or a regular spinning disk HDD. However, they will always ensure that you can use whatever you want, as long as the hard drive has a SATA interface standard to be able to be attached to the motherboard. Here, the SATA interface standard is the interface, and SSD or spinning disk HDD is the specific implementation.",[16,174,175],{},"In programming, when applying this principle, in high-level abstract classes, we often use interfaces more than a specific inheritance type. For example, to connect to the Database, we often design the DataAccess abstract class with common methods such as save(), get(), ... Then, depending on which type of DBMS is used (eg: MySql, MongoDB, ...), we inherit and implement these methods. The polymorphic nature of OOP is heavily used in this principle.",[11,177,179],{"id":178},"conclusion","🎯 Conclusion",[20,181,182,196,209,221],{},[23,183,184,189,190,195],{},[26,185,186],{},[29,187,188],{},"Clear, Understand",": ",[26,191,192],{},[29,193,194],{},"SOLID"," are 5 basic principles in software design. It helps us organize functions, methods, classes more accurately. How to connect components, modules together.",[23,197,198,203,204,208],{},[26,199,200],{},[29,201,202],{},"Teamwork",": Apply ",[26,205,206],{},[29,207,194],{}," in your work, you will create better, easier-to-understand functions. Helping you and your colleagues read each other's code better.",[23,210,211,189,216,220],{},[26,212,213],{},[29,214,215],{},"Changeable",[26,217,218],{},[29,219,194],{}," helps create clear, coherent, highly independent modules and classes. Therefore, when there is a request for change or expansion from customers, we do not have to spend too much effort to make the change.",[23,222,223,189,228,232],{},[26,224,225],{},[29,226,227],{},"Reusable",[26,229,230],{},[29,231,194],{}," makes programmers think more about how to write software, so the code written will be coherent, easy to understand, and easy to use.",{"title":78,"searchDepth":234,"depth":234,"links":235},2,[236,237,238,239],{"id":13,"depth":234,"text":14},{"id":62,"depth":234,"text":63},{"id":168,"depth":234,"text":169},{"id":178,"depth":234,"text":179},"tutorial","Introduction to concepts of SOLID pattern in object-oriented programming",7,"md",{"src":245,"alt":246},"https:\u002F\u002Fraw.githubusercontent.com\u002Ffullstack-core\u002Fblog\u002Frefs\u002Fheads\u002Fmain\u002Fblog\u002Fcover\u002Fwhat-is-solid.webp","SOLID image",{},"\u002Fposts\u002Ftutorial\u002Fwhat-is-solid","2024-12-24",{"title":5,"description":241},{"loc":248,"lastmod":249},"posts\u002Ftutorial\u002Fwhat-is-solid",[240,254],"nocode",false,"TIXqDHd7XFPp0N18Y_pVkylAV77pawrBvDtcQmdLjyo",[258,374,382,521],{"title":259,"icon":260,"path":261,"stem":262,"children":263,"page":255},"Cheatsheets","fluent-color:paw-16","\u002Fcheatsheets","cheatsheets",[264,269,274,279,284,289,294,299,304,309,314,319,324,329,334,339,344,349,354,359,364,369],{"title":265,"path":266,"stem":267,"icon":268},"Bash","\u002Fcheatsheets\u002Fbash","cheatsheets\u002Fbash","material-icon-theme:powershell",{"title":270,"path":271,"stem":272,"icon":273},"CSS","\u002Fcheatsheets\u002Fcss","cheatsheets\u002Fcss","vscode-icons:file-type-css2",{"title":275,"path":276,"stem":277,"icon":278},"Docker","\u002Fcheatsheets\u002Fdocker","cheatsheets\u002Fdocker","vscode-icons:file-type-docker2",{"title":280,"path":281,"stem":282,"icon":283},"Git","\u002Fcheatsheets\u002Fgit","cheatsheets\u002Fgit","devicon:git",{"title":285,"path":286,"stem":287,"icon":288},"Golang","\u002Fcheatsheets\u002Fgo","cheatsheets\u002Fgo","material-icon-theme:go",{"title":290,"path":291,"stem":292,"icon":293},"HTML","\u002Fcheatsheets\u002Fhtml","cheatsheets\u002Fhtml","material-icon-theme:html",{"title":295,"path":296,"stem":297,"icon":298},"JavaScript","\u002Fcheatsheets\u002Fjavascript","cheatsheets\u002Fjavascript","material-icon-theme:javascript",{"title":300,"path":301,"stem":302,"icon":303},"Latex","\u002Fcheatsheets\u002Flatex","cheatsheets\u002Flatex","material-icon-theme:latexmk",{"title":305,"path":306,"stem":307,"icon":308},"Linux","\u002Fcheatsheets\u002Flinux","cheatsheets\u002Flinux","devicon:linux",{"title":310,"path":311,"stem":312,"icon":313},"Markdown","\u002Fcheatsheets\u002Fmarkdown","cheatsheets\u002Fmarkdown","material-icon-theme:markdown",{"title":315,"path":316,"stem":317,"icon":318},"Mongo","\u002Fcheatsheets\u002Fmongo","cheatsheets\u002Fmongo","devicon:mongodb",{"title":320,"path":321,"stem":322,"icon":323},"Nest","\u002Fcheatsheets\u002Fnest","cheatsheets\u002Fnest","material-icon-theme:nest",{"title":325,"path":326,"stem":327,"icon":328},"Next","\u002Fcheatsheets\u002Fnext","cheatsheets\u002Fnext","logos:nextjs-icon",{"title":330,"path":331,"stem":332,"icon":333},"Node","\u002Fcheatsheets\u002Fnode","cheatsheets\u002Fnode","material-icon-theme:nodejs",{"title":335,"path":336,"stem":337,"icon":338},"Nuxt","\u002Fcheatsheets\u002Fnuxt","cheatsheets\u002Fnuxt","material-icon-theme:nuxt",{"title":340,"path":341,"stem":342,"icon":343},"React","\u002Fcheatsheets\u002Freact","cheatsheets\u002Freact","material-icon-theme:react",{"title":345,"path":346,"stem":347,"icon":348},"Redis","\u002Fcheatsheets\u002Fredis","cheatsheets\u002Fredis","vscode-icons:folder-type-redis-opened",{"title":350,"path":351,"stem":352,"icon":353},"SQL","\u002Fcheatsheets\u002Fsql","cheatsheets\u002Fsql","material-icon-theme:database",{"title":355,"path":356,"stem":357,"icon":358},"Typescript","\u002Fcheatsheets\u002Ftypescript","cheatsheets\u002Ftypescript","material-icon-theme:typescript",{"title":360,"path":361,"stem":362,"icon":363},"Vercel","\u002Fcheatsheets\u002Fvercel","cheatsheets\u002Fvercel","vscode-icons:file-type-light-vercel",{"title":365,"path":366,"stem":367,"icon":368},"Vue","\u002Fcheatsheets\u002Fvue","cheatsheets\u002Fvue","material-icon-theme:vue",{"title":370,"path":371,"stem":372,"icon":373},"Windows","\u002Fcheatsheets\u002Fwindow","cheatsheets\u002Fwindow","material-icon-theme:folder-windows",{"title":375,"icon":260,"path":376,"stem":377,"children":378,"page":255},"Interviews","\u002Finterviews","interviews",[379],{"title":290,"path":380,"stem":381,"icon":293},"\u002Finterviews\u002Fhtml","interviews\u002Fhtml",{"title":383,"icon":384,"path":385,"stem":386,"children":387,"page":255},"Posts","fluent-color:data-bar-vertical-ascending-24","\u002Fposts","posts",[388,397,413,439,447,460,469,478,488,511],{"title":389,"icon":353,"redirect":390,"path":391,"stem":392,"children":393,"page":255},"Database","\u002Fposts\u002Fdatabase\u002Freplication-strategy","\u002Fposts\u002Fdatabase","posts\u002Fdatabase",[394],{"title":395,"path":390,"stem":396,"icon":6},"Database Replication strategy in large systems","posts\u002Fdatabase\u002Freplication-strategy",{"title":275,"icon":278,"redirect":398,"path":399,"stem":400,"children":401,"page":255},"\u002Fposts\u002Fdocker\u002Fdocker-commands","\u002Fposts\u002Fdocker","posts\u002Fdocker",[402,405,409],{"title":403,"path":398,"stem":404,"icon":6},"Docker commands essentials","posts\u002Fdocker\u002Fdocker-commands",{"title":406,"path":407,"stem":408,"icon":6},"Some useful Dockerfile templates","\u002Fposts\u002Fdocker\u002Fdockerfile-templates","posts\u002Fdocker\u002Fdockerfile-templates",{"title":410,"path":411,"stem":412,"icon":6},"Setup Docker environment on Windows","\u002Fposts\u002Fdocker\u002Fsetup-docker-on-window","posts\u002Fdocker\u002Fsetup-docker-on-window",{"title":414,"icon":415,"redirect":416,"path":417,"stem":418,"children":419,"page":255},"Git & GitHub","material-icon-theme:git","\u002Fposts\u002Fgit\u002Fbrightly-decorate-graph","\u002Fposts\u002Fgit","posts\u002Fgit",[420,423,427,431,435],{"title":421,"path":416,"stem":422,"icon":6},"Brightly decorate your GitHub Graph","posts\u002Fgit\u002Fbrightly-decorate-graph",{"title":424,"path":425,"stem":426,"icon":6},"Download a specific folder on GitHub repository","\u002Fposts\u002Fgit\u002Fdownload-specific-folder","posts\u002Fgit\u002Fdownload-specific-folder",{"title":428,"path":429,"stem":430,"icon":6},"Syncing Git Tags across to other repositories","\u002Fposts\u002Fgit\u002Fsyncing-tags-across-repositories","posts\u002Fgit\u002Fsyncing-tags-across-repositories",{"title":432,"path":433,"stem":434,"icon":6},"Unlocking GitHub Achievement badges","\u002Fposts\u002Fgit\u002Funlocking-achievement-badges","posts\u002Fgit\u002Funlocking-achievement-badges",{"title":436,"path":437,"stem":438,"icon":6},"Essential Git commands every developer should master","\u002Fposts\u002Fgit\u002Fuseful-commands-like-pro","posts\u002Fgit\u002Fuseful-commands-like-pro",{"title":285,"icon":288,"redirect":440,"path":441,"stem":442,"children":443,"page":255},"\u002Fposts\u002Fgolang\u002Foptimizing-performance-with-pgo","\u002Fposts\u002Fgolang","posts\u002Fgolang",[444],{"title":445,"path":440,"stem":446,"icon":6},"Optimizing Performance in Go Applications with PGO","posts\u002Fgolang\u002Foptimizing-performance-with-pgo",{"title":295,"icon":448,"redirect":449,"path":450,"stem":451,"children":452,"page":255},"vscode-icons:file-type-js","\u002Fposts\u002Fjavascript\u002F9-lines-of-tips","\u002Fposts\u002Fjavascript","posts\u002Fjavascript",[453,456],{"title":454,"path":449,"stem":455,"icon":6},"9 lines of JavaScript replace 50 lines of code","posts\u002Fjavascript\u002F9-lines-of-tips",{"title":457,"path":458,"stem":459,"icon":6},"Javascript Promises - Specific functions and use cases","\u002Fposts\u002Fjavascript\u002Fpromises-cheatsheet","posts\u002Fjavascript\u002Fpromises-cheatsheet",{"title":330,"icon":461,"redirect":462,"path":463,"stem":464,"children":465,"page":255},"material-icon-theme:nodejs-alt","\u002Fposts\u002Fnodejs\u002Fevent-loop","\u002Fposts\u002Fnodejs","posts\u002Fnodejs",[466],{"title":467,"path":462,"stem":468,"icon":6},"Secret about Event Loop flow in Nodejs","posts\u002Fnodejs\u002Fevent-loop",{"title":335,"icon":470,"redirect":471,"path":472,"stem":473,"children":474,"page":255},"vscode-icons:file-type-nuxt","\u002Fposts\u002Fnuxt\u002Fenable-pwa-in-nuxt","\u002Fposts\u002Fnuxt","posts\u002Fnuxt",[475],{"title":476,"path":471,"stem":477,"icon":6},"Enable PWA and Service Worker in Nuxt","posts\u002Fnuxt\u002Fenable-pwa-in-nuxt",{"title":479,"icon":480,"redirect":481,"path":482,"stem":483,"children":484,"page":255},"Performance","emojione:rocket","\u002Fposts\u002Fperformance\u002Fbackground-image-injection-problem","\u002Fposts\u002Fperformance","posts\u002Fperformance",[485],{"title":486,"path":481,"stem":487,"icon":6},"Background-Image injection problem in UX","posts\u002Fperformance\u002Fbackground-image-injection-problem",{"title":489,"icon":490,"redirect":491,"path":492,"stem":493,"children":494,"page":255},"Tutorial","fluent-color:book-open-lightbulb-24","\u002Fposts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers","\u002Fposts\u002Ftutorial","posts\u002Ftutorial",[495,498,502,506,510],{"title":496,"path":491,"stem":497,"icon":6},"Classification and functionality of the servers","posts\u002Ftutorial\u002Fclassification-and-functionality-of-the-servers",{"title":499,"path":500,"stem":501,"icon":6},"What is the difference between localhost and 127.0.0.1?","\u002Fposts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1","posts\u002Ftutorial\u002Fdifferent-between-localhost-and-127-0-0-1",{"title":503,"path":504,"stem":505,"icon":6},"8 essential network protocols every programmer should know","\u002Fposts\u002Ftutorial\u002Fessential-network-protocols","posts\u002Ftutorial\u002Fessential-network-protocols",{"title":507,"path":508,"stem":509,"icon":6},"Pre rels in header link tag - SEO technique enhancement","\u002Fposts\u002Ftutorial\u002Fpre-rels-in-header-link-tag","posts\u002Ftutorial\u002Fpre-rels-in-header-link-tag",{"title":5,"path":248,"stem":252,"icon":6},{"title":512,"icon":513,"redirect":514,"path":515,"stem":516,"children":517,"page":255},"UI\u002FUX","devicon:figma","\u002Fposts\u002Fuiux\u002Fcommon-button-mistake","\u002Fposts\u002Fuiux","posts\u002Fuiux",[518],{"title":519,"path":514,"stem":520,"icon":6},"Common Button Mistake in UI\u002FUX","posts\u002Fuiux\u002Fcommon-button-mistake",{"title":522,"icon":523,"path":524,"stem":525,"children":526,"page":255},"Templates","fluent-color:data-pie-24","\u002Ftemplates","templates",[527,530,533,536,539],{"title":285,"path":528,"stem":529,"icon":288},"\u002Ftemplates\u002Fgo","templates\u002Fgo",{"title":325,"path":531,"stem":532,"icon":328},"\u002Ftemplates\u002Fnext","templates\u002Fnext",{"title":335,"path":534,"stem":535,"icon":338},"\u002Ftemplates\u002Fnuxt","templates\u002Fnuxt",{"title":340,"path":537,"stem":538,"icon":343},"\u002Ftemplates\u002Freact","templates\u002Freact",{"title":365,"path":540,"stem":541,"icon":368},"\u002Ftemplates\u002Fvue","templates\u002Fvue",[543,544],{"title":507,"path":508,"stem":509,"children":-1},{"title":519,"path":514,"stem":520,"children":-1},[546,555,562],{"_path":500,"title":499,"description":547,"image":548,"category":240,"tags":551,"duration":553,"publishedAt":554},"Introduction to the concepts of localhost and 127.0.0.1 in networking",{"src":549,"alt":550},"https:\u002F\u002Fi.ytimg.com\u002Fvi\u002F91PrPbuHdhg\u002Fmaxresdefault.jpg","localhost_and_127.0.0.1_image",[240,552],"network",6,"2025-08-29",{"_path":504,"title":503,"description":556,"image":557,"category":240,"tags":560,"duration":242,"publishedAt":561},"What are network protocols? Explore the functions and use cases of each type of network protocol in digital communication",{"src":558,"alt":559},"https:\u002F\u002Fraw.githubusercontent.com\u002Ffullstack-core\u002Fblog\u002Frefs\u002Fheads\u002Fmain\u002Fblog\u002Fcover\u002F8-essential-network-protocols-every-programmer-should-know.webp","Protocols image",[240,552],"2025-06-16",{"_path":491,"title":496,"description":563,"image":564,"category":240,"tags":567,"duration":242,"publishedAt":568},"What is server? Functions of popular servers nowadays.",{"src":565,"alt":566},"https:\u002F\u002Fraw.githubusercontent.com\u002Ffullstack-core\u002Fblog\u002Frefs\u002Fheads\u002Fmain\u002Fblog\u002Fcover\u002Fclassification-and-functionality-of-the-servers.webp","Server image",[240,552],"2025-02-26"]