Graduate Program KB

Clean Architecture

Chapter 10 - ISP: The Interface Segregation Principle

  • ISP advices software designers to avoid depending on things that they don't use
  • In Figure 10.1, User1 depends on an Ops class which has 3 methods but User1 only uses one
    • The issue is changes to the other 2 methods will cause User1 to recompile despite it not utilising that functionality
    • This can be solved by segregating operations into different interfaces (User1 depends on a OpsMethod1 interface for example)

ISP and Language

  • Statically typed languages force programmers to create declarations (import, use, include) which create dependencies that force recompilation and redeployment
  • Dynamically typed languages don't have declarations (inferred at runtime), so there are no source code dependencies to force recompilation and redeployment
    • Create more flexible systems that are less coupled
  • ISP is still an architectural issue despite it seemingly like a language issue

ISP and Architecture

  • At a module level, it's unnecessary to depend on modules that contain more functionality than you need
  • At an architectural level, unnecessary features may cause a chain reaction of recompilation and redeployment of components which other components may also depend on... and so on

Conclusion

  • Depending on modules which contain too much functionality can cause unnecessary trouble you don't expect