This project is a lightweight C++ application that demonstrates the Dependency Injection (DI) design pattern. It illustrates how to achieve Inversion of Control (IoC) to build a loosely coupled, highly cohesive messaging system that currently supports Email and SMS services.
By leveraging strict Object-Oriented Programming (OOP) principles and modern C++ memory management, this architecture ensures scalable, maintainable, and testable application development.
This is a personal project I built while studying the Dependency Injection design pattern.
- Dependency Injection: Services are injected into consumers via constructor injection, eliminating hard-coded dependencies.
- Interface-Driven Design: Clear abstraction using
IMessageService,IConsumer, andIMessageServiceInjectorinterfaces. - Safe Memory Management: Extensively utilizes modern C++ smart pointers (
std::unique_ptrandstd::move) to manage object lifecycles on the heap safely, preventing memory leaks. - Open/Closed Principle: The system is open for extension but closed for modification. New message types (e.g., Push Notifications) can be integrated without altering existing consumer logic.
messaging_project/
├── CMakeLists.txt
├── include/
│ ├── IMessageService.h
│ ├── IConsumer.h
│ ├── IMessageServiceInjector.h
│ ├── EmailService.h
│ ├── SMSService.h
│ ├── MyDIApplication.h
│ ├── EmailServiceInjector.h
│ └── SMSServiceInjector.h
└── src/
├── EmailService.cpp
├── SMSService.cpp
├── MyDIApplication.cpp
├── EmailServiceInjector.cpp
├── SMSServiceInjector.cpp
└── main.cpp