English How-To

By Reference vs By Pointer Dependency Injection C++

By Reference DI is safer because reference cannot be Null, but it has some issues: initialization, copying, and assignment problem. Something that I’m currently experience now.

By Pointer DI has no issues above, but by using pointer reference you will need to watch some issues like object ownership (where Smart Pointer is better), and null-value (always remember to assert dependencies != nullptr)

Leave a Reply

Your email address will not be published. Required fields are marked *