- 🏋️♂️ This lab demonstrates the concepts of dependency injection (DI) and inversion of control (IoC) in Java. It provides both a static and dynamic presentation of how dependencies can be injected into classes.
- Static Presentation: Use static instantiation to create instances of DOA and Business implementations and inject dependencies using setter methods.
- Dynamic Presentation: Read configuration from a file and dynamically instantiate DAO and Business implementations based on class names specified in the config.txt file.
- Interface Abstraction: Define contracts through the IBusiness and IDao interfaces for loose coupling and easy swapping of implementations.
- Multiple Implementations: Support multiple implementations of IDao and IBusiness interfaces for retrieving data from different sources.
- File Configuration: Configure the application behavior by specifying implementations in the configuration file config.txt, allowing for easy modification without code changes.
dependency-injection-demo/
│
├── src/
│ ├── business/
│ │ ├── IBusiness.java
│ │ └── BusinessImpl.java
│ │
│ ├── dao/
│ │ ├── IDao.java
│ │ └── DaoImpl_A.java
│ │
│ ├── extension/
│ │ ├── DaoImpl_B.java
│ │ └── DaoImpl_C.java
│ │
│ ├── presentation/
│ │ ├── DynamicPresentation.java
│ │ └── StaticPresentation.java
│ │
│ └── Main.java
│
├── config.txt
└── README.md
- For any inquires or feedback regarding this project, please contact me on: chouaib.tmane@hotmail.com.
End
Author: Tmane Chouaib