Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Single-responsibility principle meets the real ...

Single-responsibility principle meets the real world!

Presented at BlrDroid + BlrKotlin meetup on Aug 19, 2023.

"No plan survives contact with the enemy." goes an adage. This is sadly true for most software engineering principles too. Developers must constantly work against entropy to restore order in their codebases.

SOLID principles have guided many developers to validate their solutions and have helped many build maintainable software systems. However, it can be daunting to practice in the real world without constant feedback, upskilling, and support from peers and tooling.

In this talk, we aim to take a closer look at the first of the five object-oriented design principles from SOLID—Single-responsibility principle. We'll look at large classes and how they violate SRP. We'll also discuss insights and heuristics to identify each of these responsibilities.

What's good comes out of mere insights and heuristics? We'll also put these to good use in practice. At the end of the session, we'll pick one of the most popular messaging apps on Android and do the following,

- Visualize it with tooling
- Identify multiple responsibilities
- Discuss code smells
- Extract at least one responsibility into a separate class without tests

Ragunath Jawahar

August 19, 2023
Tweet

More Decks by Ragunath Jawahar

Other Decks in Programming

Transcript

  1. Single-responsibility principle • Every class should have only one responsibility

    • A class should have only one reason to change • A module should be responsible to one, and only one, actor @ragunathjawahar / legacycode.com
  2. Why do we have large classes? • Code smells •

    Long methods • Feature-envy • Too many methods/functions • Missing abstraction • Duplication • Primitive obsession • Data clumps • … • Developer churn • No tests • Cross-cutting concerns • Utilities • High-level classes
  3. Why do we have large classes? • Code smells •

    Long methods • Feature-envy • Too many methods/functions • Missing abstraction • Duplication • Primitive obsession • Data clumps • … • Developer churn • No tests • Cross-cutting concerns • Utilities • High-level classes
  4. High-level classes The term "high-level classes" typically refers to classes

    that operate at a higher level of abstraction compared to other classes in the system. They generally encapsulate broad concepts, complex behaviors, or orchestration tasks rather than speci fi c, detailed implementations. @ragunathjawahar / legacycode.com
  5. High-level classes The term "high-level classes" typically refers to classes

    that operate at a higher level of abstraction compared to other classes in the system. They generally encapsulate broad concepts, complex behaviors, or orchestration tasks rather than speci fi c, detailed implementations. @ragunathjawahar / legacycode.com
  6. High-level classes The term "high-level classes" typically refers to classes

    that operate at a higher level of abstraction compared to other classes in the system. They generally encapsulate broad concepts, complex behaviors, or orchestration tasks rather than speci fi c, detailed implementations. @ragunathjawahar / legacycode.com
  7. High-level classes The term "high-level classes" typically refers to classes

    that operate at a higher level of abstraction compared to other classes in the system. They generally encapsulate broad concepts, complex behaviors, or orchestration tasks rather than speci fi c, detailed implementations. @ragunathjawahar / legacycode.com
  8. High-level classes The term "high-level classes" typically refers to classes

    that operate at a higher level of abstraction compared to other classes in the system. They generally encapsulate broad concepts, complex behaviors, or orchestration tasks rather than speci fi c, detailed implementations. @ragunathjawahar / legacycode.com
  9. High-level classes The term "high-level classes" typically refers to classes

    that operate at a higher level of abstraction compared to other classes in the system. They generally encapsulate broad concepts, complex behaviors, or orchestration tasks rather than speci fi c, detailed implementations. @ragunathjawahar / legacycode.com
  10. TLDR; They just have too many things to do 🤷

    @ragunathjawahar / legacycode.com
  11. —Albert Einstein “We cannot solve our problems with the same

    thinking we used when we created them.”
  12. Do • Use IDE-assisted refactoring • Use a git GUI

    client • Use micro-commits with Arlo Belshee’s commit notation • Pair/ensemble program • Verify manually
  13. Don’t • Have long running branches • Push it too

    far @ragunathjawahar / legacycode.com