{"id":267,"date":"2023-05-05T07:00:16","date_gmt":"2023-05-05T07:00:16","guid":{"rendered":"https:\/\/archicode.be\/?p=267"},"modified":"2023-05-04T07:47:39","modified_gmt":"2023-05-04T07:47:39","slug":"single-responsability-vs-interface-segregation","status":"publish","type":"post","link":"https:\/\/archicode.be\/index.php\/2023\/05\/05\/single-responsability-vs-interface-segregation\/","title":{"rendered":"Single responsability vs Interface segregation"},"content":{"rendered":"\n<p>I stumbled upon a Reddit post forwarding an article about how single responsability and interface segregation would be essentially the same.  I obviously disagreed but by reading the comments, it appeared that the differences between the two aren&#8217;t that clear for some<\/p>\n\n\n\n<p>Let&#8217;s start with the single responsability.  It means that a class has one and one reason for change only.  Regardless of dependencies or things that it uses.  The reason for change cannot be external.  In reality it&#8217;s not entirely possible especially if the signature of a method changes in a dependency, but the idea is there.<\/p>\n\n\n\n<p>The interface segregation means that interfaces should be small and very specific instead of using one big interface.  This will allow also to reduce the risk of having a method signature change that would require a change in a class using that interface.  <\/p>\n\n\n\n<p>The interface segregation respects indeed the single responsability principle but is about interfaces and them being very specific in what they do.  Like in his example in his book, Uncle Bob (Robert C. Martin) explains how from an interface that does a lot, it splits it in smaller interfaces that manage money withdrawal, money deposit, etc.<\/p>\n\n\n\n<p>You could very well have one class that respects the single responsibility but whose interface will be extensive and violates the interface segregation.  So the idea would be to have a class implementing different interfaces so the classes using the interfaces would only use the needed methods.<\/p>\n\n\n\n<p>Another example would be a repository class that has read and write methods but implementing two interfaces, IRepositoryRead and IRepositoryWrite.  That way, any client will use either interface or both, but the interfaces will be small and specific thus agreeing with the interface segregation but the Repository class will also agree with the Single Responsability pattern.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I stumbled upon a Reddit post forwarding an article about how single responsability and interface segregation would be essentially the same. I obviously disagreed but by reading the comments, it appeared that the differences between the two aren&#8217;t that clear for some Let&#8217;s start with the single responsability. It means that a class has one&#8230;<\/p>\n","protected":false},"author":1,"featured_media":271,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[31,30],"class_list":["post-267","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-patterns","tag-solid"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/archicode.be\/wp-content\/uploads\/2023\/05\/1_VI8o7tE-jtcFp4Z837KJIQ-1.jpg","jetpack-related-posts":[{"id":340,"url":"https:\/\/archicode.be\/index.php\/2023\/11\/15\/single-responsibility-principle-clearn-architecture\/","url_meta":{"origin":267,"position":0},"title":"Single Responsibility Principle (Clean Architecture)","author":"Hakim","date":"November 15, 2023","format":false,"excerpt":"When talking about patterns, almost everyone can name the SOLID pattern (Single Responsability, Open\/Close, Liskov Substitution, Interface Segregation and Dependency Inversion). The Single Reponsibility is one of the most important principle for clean code but it's also very important for clean architecture. Let's explore this The SRP states that a\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/11\/8a4f15b6-f5a9-4579-a2aa-6b95d588c817.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":353,"url":"https:\/\/archicode.be\/index.php\/2023\/12\/03\/the-reuse-release-equivalence-principle-a-key-to-modular-design\/","url_meta":{"origin":267,"position":1},"title":"The Reuse\/Release Equivalence Principle: A Key to Modular Design","author":"Hakim","date":"December 3, 2023","format":false,"excerpt":"One of the challenges of software development is to create reusable and maintainable code. Reusable code can reduce duplication, improve quality, and save time and resources. Maintainable code is code that is easy to adapt, easy to correct and where those adaptation and change do not break any other part\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":324,"url":"https:\/\/archicode.be\/index.php\/2023\/11\/07\/how-to-use-feature-flags-in-blazor\/","url_meta":{"origin":267,"position":2},"title":"How to use Feature Flags in Blazor","author":"Hakim","date":"November 7, 2023","format":false,"excerpt":"Feature flags are a way of controlling the availability and behavior of features in your application without changing the code. They can help you with testing, experimentation, and gradual rollout of new functionality. Blazor is a framework for building interactive web UIs using C# and .NET. In this blog post,\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/11\/4b6f8d86-a588-4313-8cc9-4c41a90aaae5.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/11\/4b6f8d86-a588-4313-8cc9-4c41a90aaae5.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/11\/4b6f8d86-a588-4313-8cc9-4c41a90aaae5.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/archicode.be\/wp-content\/uploads\/2023\/11\/4b6f8d86-a588-4313-8cc9-4c41a90aaae5.jpeg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":164,"url":"https:\/\/archicode.be\/index.php\/2020\/07\/15\/working-with-legacy-databases\/","url_meta":{"origin":267,"position":3},"title":"Working with Legacy databases","author":"Hakim","date":"July 15, 2020","format":false,"excerpt":"It does not happen everyday that as a developer we start working on a greenfield project. On many occasions, we have maintenance work to do on existing projects or we are rewriting an old application into microservices. What happens during these brownfield projects is that we have to cope with\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/archicode.be\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":349,"url":"https:\/\/archicode.be\/index.php\/2023\/11\/25\/use-case-pattern\/","url_meta":{"origin":267,"position":4},"title":"Use Case Pattern","author":"Hakim","date":"November 25, 2023","format":false,"excerpt":"The Use Case Pattern is a way of organizing the business logic of an application into a set of use cases. Each use case represents a specific action that a user can perform within the system. For example, in an e-commerce application, a use case might be \u201cPlace an Order\u201d\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":92,"url":"https:\/\/archicode.be\/index.php\/2019\/06\/10\/how-to-blazorify-an-existing-mvc-app\/","url_meta":{"origin":267,"position":5},"title":"How to blazorify an existing mvc app","author":"Hakim","date":"June 10, 2019","format":false,"excerpt":"Blazor is awesome. \u00a0If you don't know what it is, you can check it out here\u00a0but to summarize, it's a framework that allows .net code to run in your browser using the power of Web Assembly. I've found a lot of tutorials using the official blazor templates but only hints\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/archicode.be\/index.php\/category\/net\/"},"img":{"alt_text":"migrate_solution_to_dotnet_core_3.gif","src":"\/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 1x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 1.5x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 2x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 3x, \/wp-content\/uploads\/2019\/06\/migrate_solution_to_dotnet_core_3.gif 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/posts\/267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/comments?post=267"}],"version-history":[{"count":2,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/posts\/267\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/posts\/267\/revisions\/269"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/media\/271"}],"wp:attachment":[{"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/media?parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/categories?post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archicode.be\/index.php\/wp-json\/wp\/v2\/tags?post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}