This document discusses dependency injection (DI) and dependency inversion as techniques for improving software design. It explains that DI provides objects their dependencies rather than having them instantiate dependencies directly. This loosens coupling between objects. Dependency inversion defines objects by their abstractions rather than concretions, making objects more adaptable to change. The document provides examples of implementing DI using libraries like Koin and discusses how DI and dependency inversion together can improve software qualities like reusability and maintainability.
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
Improving SOC and Reusability with Dependency Injection and Inversion
1. Sidiq Permana
CIO Nusantara Beta Studio, Google Developer Expert Android
Meningkatkan SOC dan Reusabillity Kode
dengan Duo DI
2. What is the something fun in developing
the software?
Facing Uncertainty of
Business Changes!
3. As the outcome what kind of software
do you want to achieve?
● Deliver the business value and improve the business sustainability.
● A software that flexibly to adapt to changes, not giving major defect
and less effort to adjust.
● Robust, Scalable, Durable, Easy to Maintain and Reusable
components.
4. Good Software Design is to Avoid
Rigidity : Hard to change. Too Risky!
Fragility : Small changes defects many.
Immobility : Inability to reuse the components.
10. Good software design will determine and be measured by
the required effort to change, maintain, and adapt the
existing software to business uncertainty.
11.
12. ● “High-level modules should not depend on low-level modules. Both should depend on
abstractions.”
● “Abstractions should not depend on details. Details should depend on abstractions.”
Source Code Dependencies Refers
To Abstraction, Not to Concretions.
Abstraction is less to change while the concretion is volatile.
13. 1. Don't Refer to Volatile Concrete Classes. Refer to Interface Abstraction
Instead.
2. Don’t Derive From Concrete Classes. More care and attention to Inheritance.
3. Don’t Override Concrete Functions. Make it abstract.
4. Never mention the Name of Anything Concrete and Volatile. Restatement
depends upon Abstraction.
Stable Abstractions
21. Dependency Injection is one of inversion control (others :
service locator, strategy pattern, factory pattern) technique
whereby one object (or static method) supplies the
dependencies of another object. A dependency is an object
that can be used (a service).
22. ● Helps us enable loose coupling.
● Reduces the boilerplate code.
● Reusable and clean code.
● Easy to replace dependencies
with fake implementations.
● Easier to test.
Why do we need DI ?
32. Dependency Injection == “Give me it” and Dependency
Inversion == “Someone take care of this for me,
somehow.”
Dependency Injection is about supplying the objects while
Dependency Inversion is taking care the implementation of the
abstract.
33. ● Dependency Inversion != Dependency Injection but these two are able to work
together to improve SOC and Reusability.
● Dependency Inversion offers the flexibility to extend the function through the
abstraction without breaking the existing classes. So it goes along with open/close
principles.
● Dependency Inversion forces you to define the behaviour of the object to make it
more scalable, easy to maintain and adapt with changes and of course avoid you from
fragility!
● Dependency Injection avoids you to have hard dependency and avoid you to Rigidity.
So many faedah when you are using it.
● Too many available DI libraries that you can use to do DI with their positive and
negative to fit your needs and expectation.
Conclusion
34. DON’T MISS IT!
Kalau ada yg punya pertanyaan
dan mau dijawab live bisa
langsung komentar di tweet ini
ya
https://bit.ly/ask-android11