Reusability and Dependency Injection

Rafael A. George Duval
2 min readOct 28, 2023

--

Managing dependencies is the key concept behind object-oriented design. It involves organizing coding techniques to enable objects to handle changes. Applications that are challenging to change can be frustrating to work on. This is why design is so important — it allows for necessary changes.

Neglecting design can lead to problems down the line. Thus, assessing your skills and available time is essential when deciding how much design work to undertake. The ultimate goal is to produce software with the most features while minimizing costs.

Flannery O’Connor said that anyone who survived childhood has enough material to write for the rest of his or her life.

Isolate Dependencies. It is not the class of the object that’s important. It’s the message you plan to send to it. If you are mindful of dependencies and develop a habit of injecting them, your classes will be loosely coupled. In contrast, one whose class name dependencies are concise, explicit, and isolated can adapt to new requirements. This technique becomes necessary when a class contains embedded references to a message likely to change. Isolating the reference provides some insurance against being affected by that change. By injecting dependencies, we can ensure that our code is testable and decoupled, making it easier to reason about and change. The cost of implementing dependency injection is low, while its benefits are significant.

[¹]: Practical Object-Oriented Design: An Agile Primer Using Ruby

--

--

Rafael A. George Duval
Rafael A. George Duval

Written by Rafael A. George Duval

✍🏼 Building a Solo Digital Media Company 🧪 Snippets of Text [https://snippetsoftext.substack.com/subscribe]

No responses yet