Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is it in the C++ culture to use Dependency Injection/Inversion ofControl?

Reply
Thread Tools

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

 
 
Danno
Guest
Posts: n/a
 
      04-09-2008
On Apr 9, 6:12 am, Lloyd Bonafide <(E-Mail Removed)> wrote:
> Ian Collins <(E-Mail Removed)> wrote in news:663cgoF2hu9ejU9
> @mid.individual.net:
>
> > Danno wrote:
> >> On Apr 8, 7:13 pm, Ian Collins <(E-Mail Removed)> wrote:
> >>> Danno wrote:
> >>>> Just that simple question....out of curiosity.
> >>> 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. >
> >> C++ classes don't support dynamic binding,

>
> 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/



 
Reply With Quote
 
 
 
 
Danno
Guest
Posts: n/a
 
      04-09-2008
On Apr 9, 2:19 am, Ian Collins <(E-Mail Removed)> wrote:
> Danno wrote:
> > On Apr 8, 7:13 pm, Ian Collins <(E-Mail Removed)> wrote:
> >> Danno wrote:
> >>> Just that simple question....out of curiosity.
> >> 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.

>
> 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.

> 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.
>





 
Reply With Quote
 
 
 
 
Ke Jin
Guest
Posts: n/a
 
      04-10-2008
On Apr 8, 6:07*pm, Danno <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Rob Dob ASP .Net Web Controls 0 11-27-2005 03:57 PM
[MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Rob Dob ASP .Net 0 11-27-2005 03:57 PM
Can I use .manifest in ASP.NET for dependency control =?Utf-8?B?amFtaWVj?= ASP .Net 0 10-04-2005 06:31 PM
use / circular dependency issue Jens Luedicke Perl Misc 6 07-15-2005 11:43 AM
Nasty bug in documentation regarding globalization - wrong Culture Info name for Serbian (Cyrilic) Dejan Vesic ASP .Net 1 07-03-2003 12:32 AM



Advertisments