Is it in the C++ culture to use Dependency Injection/Inversion ofControl?

J

Juha Nieminen

Danno said:
Just that simple question....out of curiosity.

Two things:

1) It's common netiquette to write the contents of the post in the
body of the post, not in its subject. The subject line is just a quick
intro to the post itself, it's not the post. The post should be
completely understandable even if the subject line was completely removed.

2) You are clearly trying to be a smart-ass by using complicated
terminology that only few people are acquainted with, clearly on
purpose. If you don't want people to think you are a smart-ass, explain
your terminology before using it.
 
D

Danno

Which is?

Well, the seminal articles are by Martin Fowler.
http://martinfowler.com/bliki/InversionOfControl.html
http://martinfowler.com/articles/injection.html

It is a way of designing classes, therefore objects, to be injected
with what they need instead of tight coupling relationships to other
classes & objects by instantiation or non-abstract assignements. This
is also usually done with abstractions (interface oriented design).
In Java and Ruby, objects are injected with the objects they require
by text, xml, or dsl file.
 
D

Danno

Two things:

1) It's common netiquette to write the contents of the post in the
body of the post, not in its subject. The subject line is just a quick
intro to the post itself, it's not the post. The post should be
completely understandable even if the subject line was completely removed.

2) You are clearly trying to be a smart-ass by using complicated
terminology that only few people are acquainted with, clearly on
purpose. If you don't want people to think you are a smart-ass, explain
your terminology before using it.

Calm down, my god, this group is too egotistical, pious and angry.

I am trying to educate myself with different languages and I asked one
simple question here on c.l.c++ a couple of weeks ago about pointers
and I get jumped on by one of your members. Now I ask another question
about DI/IoC and you think it's an affront to your intelligence? Are
you guys that sensitive and insecure about yourselves to go bashing
posters?

Don't worry, this will be last participation in this group for me, you
guys can proceed with your "don't hit your ass on the way out" party.
There are plenty open academic discussion groups out there.
 
D

Danno

[Subject] : Is it in the C++ culture to use Dependency Injection/
Inversion of Control?
Just that simple question....out of curiosity.

If you are hinting towards AOP, you could refer this:http://www.aspectc.org/

No, but that is some great info, and I appreciate the link.

I posted the info on Dependency Injection and Inversion of Control on
the response to Ian.
 
I

Ian Collins

Danno said:
Well, the seminal articles are by Martin Fowler.
http://martinfowler.com/bliki/InversionOfControl.html
http://martinfowler.com/articles/injection.html

It is a way of designing classes, therefore objects, to be injected
with what they need instead of tight coupling relationships to other
classes & objects by instantiation or non-abstract assignements. This
is also usually done with abstractions (interface oriented design).
In Java and Ruby, objects are injected with the objects they require
by text, xml, or dsl file.
Ah, I wasn't sure what the question was. It's been a while since I read
those papers (it's well worth spending time on Martin's site, there are
some real gems there), but I think I remember the gist.

C++ classes don't support dynamic binding, but it can be approximated
with callback functions and/or functors. SO yes, a C++ class can be
instantiated and then have specific behaviour "injected". I guess the
good old C callback functions is the most basic form of IoC.
 
A

arnuld

Calm down, my god, this group is too egotistical, pious and angry.

really ?

when I saw your post for 1st time, you seem like you were either trying to
be over-smart or you are stupid. I am not saying you are idiot/smart-ass.
I am saying the way you communicate your question to comp.lang.c++,
then it shew that way.

The way youo asked your question with *zero* words in your post reminds of
the programmers from 1late 90s "IT Revolution" era. Many persons called
themselves HTML Programmers at that time. Now I added your name onto that
list.


I am trying to educate myself with different languages and I asked one
simple question here on c.l.c++ a couple of weeks ago about pointers and
I get jumped on by one of your members. Now I ask another question about
DI/IoC and you think it's an affront to your intelligence? Are you guys
that sensitive and insecure about yourselves to go bashing posters?

No one is bashing you here. *They* are trying to educate you. Juha
Nieminen did the same and there were no harsh words in his reply.

Don't worry, this will be last participation in this group for me, you
guys can proceed with your "don't hit your ass on the way out" party.
There are plenty open academic discussion groups out there.

yes, they are there. comp.lang.c++ is a kind of group where
regular-posters are much more matured, intelligent and patient than what
you will experience on other groups.

try yourself but it will take a lot of personal-time of yours before you
find that out.





-- http://lispmachine.wordpress.com/

Please remove capital 'V's when you reply to me via e-mail.
 
L

Lloyd Bonafide

Isn't plain old LSP an instance of DI? The client code only knows the
interface, not the implementing classes. If you link dynamically, you
can plug and play different modules.

The kind of DI used in dynamic languages like Ruby and Python (which
I've used) can lead to debugging and maintenance nightmares when your
behavior is specified in code as well as config files.
 
D

Danno

Isn't plain old LSP an instance of DI? The client code only knows the
interface, not the implementing classes. If you link dynamically, you
can plug and play different modules.

The kind of DI used in dynamic languages like Ruby and Python (which
I've used) can lead to debugging and maintenance nightmares when your
behavior is specified in code as well as config files.

That is definitely one of the major complaints about DI. Some
developers get blamed for overdoing it by making their code as
anorexic as possible.

I pulled up the DI page on wikipedia and it offers frameworks in C++:

http://code.google.com/p/autumnframework/
http://code.google.com/p/pococapsule/
http://qtioccontainer.sourceforge.net/
 
D

Danno

Ah, I wasn't sure what the question was. It's been a while since I read
those papers (it's well worth spending time on Martin's site, there are
some real gems there), but I think I remember the gist.

C++ classes don't support dynamic binding, but it can be approximated
with callback functions and/or functors.

Now I know what callback functions are, but they may have different
meaning in a C++ context (or may not). I had no clue what functors
were until you posted. I googled it and found out. It looks like that
is probably the best way to do injections.
 
K

Ke Jin

Just that simple question....out of curiosity.

In C++ applications, it is pretty common that object dependencies are
configured (wired up) by passing depender references as input
parameters of plain old C++ constructs, static methods (e.g.
factories), setters, as well as other virtual/non-virtual member
functions of dependee objects. So, from this sense, one could claim
that dependency injection (DI) has been a C++ calture for decades.

To change the question more specific to "DI framework support in C++",
there are several of them already. For instance, the PocoCapsule
(<http://code.google.com/p/pococapsule) supports framework agnostic
plain-old C++ objects (POCO).

Hope this helps,
Ke
 

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,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top