Dependency Injection in C++

M

Michael Feathers

Why aren't there many libraries for Dependency Injection in C++. It's
been a very useful pattern in the Java community, but I run into many
teams that could use it in C++, but it never occurs to them to write a
framework to do it.

Blogged about here:
michaelfeathers.typepad.com/michael_feathers_blog/2006/10/dependency_inje.html


Michael Feathers
www.objectmentor.com
 
K

KiLVaiDeN

Michael said:
Why aren't there many libraries for Dependency Injection in C++. It's
been a very useful pattern in the Java community, but I run into many
teams that could use it in C++, but it never occurs to them to write a
framework to do it.

Blogged about here:
michaelfeathers.typepad.com/michael_feathers_blog/2006/10/dependency_inje.html


Michael Feathers
www.objectmentor.com

What about http://sourceforge.net/projects/qtioccontainer ?

It looks like it's more popular in Java, because it's pretty usefull in
multi-tiered applications.
I'll take a look to your blog sooner or later ;)

Cheers,
K
 
R

Roland Pibinger

Why aren't there many libraries for Dependency Injection in C++. It's
been a very useful pattern in the Java community, but I run into many
teams that could use it in C++, but it never occurs to them to write a
framework to do it.

It can be done as explained here:
http://www.objectmentor.com/omReports/articles/dip.pdf .
It cannot be done as in Java because fortunately C++ has no
reflection. BTW, IOC a la Spring is totally overhyped in Java land but
the counter movement will come soon (IOC trades hard compile-time
dependencies for weak run-time dependencies).
Blogged about here:
michaelfeathers.typepad.com/michael_feathers_blog/2006/10/dependency_inje.html

Testability depends on design for testability. DI doesn't
automatically enhance testabilty.

Best regards,
Roland Pibinger
 
P

prod

Roland said:
Testability depends on design for testability. DI doesn't
automatically enhance testabilty.

I partially agree. In fact, saying "IoC enhaces testability" is only
relative to the intrusive EJB pre-3.0. As IoC frameworks support
non-intrusive POJO (Plain Old Java Object), they allow business logic
beans to be tested outside their frameworks easily. In C++ world, most
applications don't use intrusive frameworks similar to the EJB pre-3.0,
therefore, the testability with or without IoC should be the same.

Regards,
Ke
 
F

F.J.K.

Michael said:
Why aren't there many libraries for Dependency Injection in C++. It's
been a very useful pattern in the Java community, but I run into many
teams that could use it in C++, but it never occurs to them to write a
framework to do it.

I read Roland Piebingers link,
http://www.objectmentor.com/omReports/articles/dip.pdf and think it's
an interesting, very flexible and "enterprisey" pattern. However, I
fail to grasp the difference from the simple rule: "Use abstract
interface classes everywhere." (Doesn't the QT framework favor this?)

I hope I'm not terribly dense but if I understand this correctly this
automatically means using "virtual" all over the place. If you are
interested in FLOPS this is a killer. Again, I might be completely
wrong, but I think on the lower software layers, this technique is
unusable performancewise. At least I personally always try to define
functional interfaces for templates and get rid of as many virtuals as
possible when writing scientific code.

So maybe JAVA has better use for it, as it is used more as an
integrative, "scripty" language than C++ ? Or maybe the C++ community
is used more to following design patterns, without a framework
enforcing it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top