{"componentChunkName":"component---src-templates-blog-post-jsx","path":"/blog/is-it-practical-to-use-interface-segregation-principle/","result":{"data":{"site":{"siteMetadata":{"name":"Huzaifa Rasheed","title":"Huzaifa Rasheed","description":"Software Engineer","about":"\n      Hey, I'm Huzaifa.\n      <br/><br/>\n      Engineer by trade, builder by instinct - I believe in owning my stack, shipping fast, and occasionally running on chai (tea) and stubbornness. I work best in that sweet spot between deep focus and fast feedback - solo or in sync with a good team.\n      <br/><br/>\n      This site's my little corner of the internet - part portfolio, part lab - where I document what I build, break, or learn.\n      <br/><br/>\n      Outside work, I'm into long walks, pixel-perfect headshots in FPS games (eventually... maybe), plants I probably overwater, and the occasional \"classified\" hobby to stay curious.\n      <br/><br/>\n      Reach out anytime - my digital door's always open. 👋\n    ","twitter":"https://twitter.com/huzRasheed","github":"https://github.com/huzaifa-99","linkedin":"https://www.linkedin.com/in/huzaifa-rasheed/","devto":"https://dev.to/huzaifa99","stackoverflow":"https://stackoverflow.com/users/12579290/huzaifa","leetcode":"https://leetcode.com/rhuzaifa","discord":"https://discordapp.com/users/rhuzaifa","email":"dev@rhuzaifa.com","projects":[{"name":"FFMpeg Web","description":"An experimental browser-based terminal that runs FFmpeg using WebAssembly, enabling media processing directly in the browser.","link":"https://ffmpeg-web.rhuzaifa.com/","github":"https://github.com/huzaifa-99/ffmpeg-web"},{"name":"Feed base 2","description":"A mini browser game where players manipulate 4-bit binary blocks to match target BCD values - part puzzle, part binary logic trainer.","link":"https://feedbase2.rhuzaifa.com/","github":"https://github.com/huzaifa-99/feed-base-2"},{"name":"Fabric browser extension","description":"A Chrome extension that injects engineered Fabric prompts directly into the ChatGPT interface for enhanced workflow automation.","link":"https://github.com/huzaifa-99/fabric-browser-extension","github":"https://github.com/huzaifa-99/fabric-browser-extension"},{"name":"Pure Cinema","description":"An experimental, tongue-in-cheek text-to-video generator that stitches together footage, synthesized voiceovers, and background music with a Node.js + ffmpeg pipeline. Not quite Hollywood, but it renders.","link":"https://cinema.rhuzaifa.com","github":null},{"name":"Aria2c Packload","description":"A Bash script for bulk downloading magnet links or torrents using aria2c - optimized for series or list-based transfers.","link":"https://github.com/huzaifa-99/aria2c-packload","github":"https://github.com/huzaifa-99/aria2c-packload"},{"name":"RSS Watchdog","description":"A lightweight Bash script that watches RSS/Atom feeds and compiles a Markdown-based reading checklist for Unix systems.","link":"https://github.com/huzaifa-99/rss-watchdog","github":"https://github.com/huzaifa-99/rss-watchdog"},{"name":"QuoteGen","description":"A quote graphic generator that produces stylized quote images with random selection and a built-in editor for customization.","link":"https://quotegen.rhuzaifa.com/","github":null},{"name":"WebRTC Video Chat","description":"A basic WebRTC-powered app enabling peer-to-peer video and audio calls between two users.","link":"https://webrtc-video-chat.rhuzaifa.com/","github":null}],"experience":null,"skills":[{"name":"Languages & Frameworks","description":"JavaScript, TypeScript, Python, Bash - Frameworks include Node.js, React, Next.js, Vue, React Native, FastAPI."},{"name":"Databases & Storage","description":"PostgreSQL, MySQL, MongoDB - Experience with schema design, indexing, query optimization, and migrations."},{"name":"Cloud & Infrastructure","description":"AWS (EC2, RDS, S3, Lambda), Vercel, Netlify, Heroku - Comfortable with serverless, autoscaling, and cost optimization."},{"name":"DevOps & Tooling","description":"Docker, Git, CI/CD pipelines (GitHub Actions, GitLab CI) - Experience with observability, containerization, and release workflows."},{"name":"Testing & QA Automation","description":"Jest, Playwright, Puppeteer, Selenium - Focus on E2E testing, mocking APIs, and maintaining test coverage."}]}},"markdownRemark":{"id":"cf474c73-f4b1-5700-b0bf-2eaa51221656","excerpt":"Repost of https://dev.to/rhuzaifa/is-it-practical-to-use-interface-segregation-principle-3ojl SOLID is a very popular design concept in programming. Interface…","html":"<blockquote>\n<p>Repost of <a href=\"https://dev.to/rhuzaifa/is-it-practical-to-use-interface-segregation-principle-3ojl\">https://dev.to/rhuzaifa/is-it-practical-to-use-interface-segregation-principle-3ojl</a></p>\n</blockquote>\n<p>SOLID is a very popular design concept in programming. Interface Segregation is part of SOLID Design. You may ask, what is <strong>SOLID?</strong></p>\n<blockquote>\n<p>SOLID are 5 software development principles or guidelines based on Object-Oriented design making it easier for you to make your projects scalable and maintainable.</p>\n</blockquote>\n<p>In code, you have best-practices and rules. SOLID designs are like best-practices.</p>\n<h3>Interface Segregation</h3>\n<p>It says</p>\n<blockquote>\n<p>Clients Should Not Be Forced To Depend Upon Interfaces That They Do Not Use.</p>\n</blockquote>\n<p>Pretty straightforward.</p>\n<h4>What This Means<br/></h4>\n<p>✔️ Create smaller and specific interfaces (role interfaces).<br/>\n❌ Classes can implement interfaces they don’t use.<br/></p>\n<h3>Why do this?</h3>\n<p>Consider</p>\n<blockquote>\n<p>A client depends upon a class that contains interfaces the client does not use, but other clients do use, then the first client will be affected by the changes other clients force upon the class used by the first client.</p>\n</blockquote>\n<p>The Goal of this principle is to avoid these situations. </p>\n<p>The pattern for other <strong>SOLID</strong> principles like <strong><a href=\"/blog/why-you-should-be-following-the-single-responsibility-principle\">Single Responsibility</a></strong> and <strong><a href=\"/blog/explained-open-close-principle-in-2-minutes\">Open Close</a></strong> is much similar <strong>:</strong> To avoid code breakages in the long run.</p>\n<h3>A Simple Use Case</h3>\n<p>Using the Bird example much similar to that discussed in <strong><a href=\"/blog/is-the-liskov-substitution-principle-really-useful\">Liskov Substitution.</a></strong></p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">Bird</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">fly</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Duck</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Bird</span><span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">fly</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n\t\t<span class=\"token comment\">// Duck can fly</span>\n\t<span class=\"token punctuation\">}</span>\t\n\t<span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n\t\t<span class=\"token comment\">// Duck can walk</span>\n\t<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Ostrich</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Bird</span><span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">fly</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n\t\t<span class=\"token comment\">// Ostrich cant fly... throw some error</span>\n\t<span class=\"token punctuation\">}</span>\t\n\t<span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n\t\t<span class=\"token comment\">// Ostrich can walk</span>\n\t<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span> </code></pre></div>\n<p>Here <code class=\"language-text\">fly()</code> is enforced to an Ostrich class by the Duck class, since both implement the same interface and Duck does use <code class=\"language-text\">fly()</code>. It is a clear violation of the Interface Segregation Principle. </p>\n<hr>\n<p>Using the Interface Segregation Principle we refactor our code to be</p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">BirdFly</span><span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">fly</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">interface</span> <span class=\"token class-name\">BirdWalk</span><span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Duck</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">BirdFly</span><span class=\"token punctuation\">,</span> BirdWalk<span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">fly</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n\t\t<span class=\"token comment\">// Duck can fly</span>\n\t<span class=\"token punctuation\">}</span>\t\n\t<span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n\t\t<span class=\"token comment\">// Duck can walk</span>\n\t<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Ostrich</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">BirdWalk</span><span class=\"token punctuation\">{</span>\n\t<span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n\t\t<span class=\"token comment\">// Ostrich can walk</span>\n\t<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span> </code></pre></div>\n<p>We have now made role-specific interfaces and there is no inadvertent coupling.</p>\n<h3>Is It Practical?</h3>\n<p>Definitely, It is best to follow this principle whenever possible. However, if your requirements are satisfied and you can work around the inadvertent coupling, then sure you can avoid this principle.</p>\n<hr>\n<p>Do you use Interface Segregation? Be sure to tell me your opinion in the comments.</p>\n<h3>What’s Next</h3>\n<p>Why The <strong><a href=\"/blog/why-the-dependency-inversion-principle-is-worth-using\">Dependency Inversion</a></strong> Principle Is Worth Using.</p>","frontmatter":{"title":"Is It Practical To Use Interface Segregation Principle?","date":"March 31, 2021","description":"Explore the Interface Segregation Principle of SOLID design, which advocates for creating specific interfaces to prevent clients from depending on methods they do not use."}}},"pageContext":{"slug":"/blog/is-it-practical-to-use-interface-segregation-principle/","previous":{"fields":{"slug":"/blog/2-simple-tips-to-clean-nested-if-else-conditions/"},"frontmatter":{"title":"2 Simple Tips To Clean Nested IF/ELSE Conditions."}},"next":{"fields":{"slug":"/blog/why-the-dependency-inversion-principle-is-worth-using/"},"frontmatter":{"title":"Why The Dependency Inversion Principle Is Worth Using"}}}},"staticQueryHashes":["2276319502"]}