1

I'm trying to understand the history of Dependency Injection in compiled languages, as an intentional feature of the language. The Wikipedia article on the subject is decidedly Java focused, but I know earlier languages supported OOP with interfaces (e.g. pure virtual methods in C++ abstract classes).

According to the design pattern described in the link, a clear requirement on the language compiler is support for something akin to type interface.

Edit: Then, polymorphism is used to morph the concrete, run-time object into the expected abstract class type used by the client.

A class (Client) accepts the objects it requires automatically at run-time.

  • A class can use objects solely through their interfaces (ServiceA,ServiceB) and doesn't have to care about how the objects are created.
  • This greatly simplifies classes and makes them easier to implement, change, test, and reuse.

Which OOP language compiler first provided this capability directly in the language's system of typing objects?

NOTE: I'm not really looking for speculations on how one might hack this in assembly, C, Fortran, etc., though that would still be interesting if it relates to the history of the feature's evolution.

closed as unclear what you're asking by Ross Ridge, JeremyP, wizzwizz4 Apr 18 at 10:03

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    > The first complete Lisp compiler, written in Lisp, was implemented in 1962 by Tim Hart and Mike Levin at MIT. – Kelvin Sherlock Apr 17 at 17:12
  • 1
    True. But a language, like Lisp, supporting first-class functions, doesn't need this design pattern, right? – Brian H Apr 17 at 17:31
  • 5
    But that's just the point, it's a design pattern. Just because it's trivial to do in the language doesn't mean it's not a valid design pattern. DI is more an external instantiation and binding mechanism than anything else. Lisp historically didn't apply this pattern, mostly because it's primary use is in testing, which wasn't common back in the day. Obj-C relied heavily on the Factory pattern for object creation, and DI is just an extension off of that. So, I guess I'm not clear as to what you're really asking here. I can't name any language that provides DI natively. Java doesn't. – Will Hartung Apr 17 at 18:00
  • 2
    The problem is realy, that this is about a design pattern. design patterns are independant of languages, they are methods of programming, not coding. And using DI is not in any way tied to OO - at least not more than adding two numbers is. – Raffzahn Apr 17 at 19:21
  • 1
    I think design patterns are crap, they're solutions in search of problems, so I've never consciously used this one or any other. However, your interpretation of the this particular design pattern doesn't agree with that of the author you linked. As is, your question doesn't make a lot of sense. Perhaps it would be better if you simply just asked what language first implemented whatever specific features you're insisting are necessary. – Ross Ridge Apr 17 at 20:39
4

Simula 67 supports abstract types so I think it could support dependency injection, I'm just not sure if it was ever used as a programming pattern.

http://rosettacode.org/wiki/Abstract_type#Simula

  • It's not clear to me whether the VIRTUAL definition represents a type usable within a client class, or not? To my understanding, some languages just treat abstract classes as templates for subclassing, rather than as interfaces. – Brian H Apr 17 at 17:01
  • 1
    @BrianH If you look at en.wikipedia.org/wiki/Simula and the example of Line and Glyph, Simula satisfies the base requirements for something that can support DI (Since Char is an implementation of Glyph, but Line is specified as using Glyphs, not Char). It's also recognized as the first object oriented language, so this would seem to be the answer you're looking for. – Will Hartung Apr 17 at 21:32
  • @WillHartung I agree. Thanks for pointing it out. Now I'm just wondering if there is such a thing as a Simula compiler... – Brian H Apr 17 at 21:43
  • @BrianH edelweb.eu/Simula "WHEN looking INTO the Internet near 2006, documentation FOR old SIMULA compilers AND even the original language definitions are difficult TO find." What makes you think it wasn't compiled? Why does compiling matter? Lisp can be compiled and interpreted. C can be compiled and interpret. BASIC can be compiled and interpreted. Some argue Java is interpreted. What difference does it make at a language level? – Will Hartung Apr 17 at 21:48
  • @WillHartung Lol, dude! Am I not allowed to have an interest in compiler history? I just didn't want to assume Simula was compiled without checking. – Brian H Apr 17 at 21:56
-3

Hmm. The main problem here is that this is about a design pattern, which are ideas how programming can/should be done. This is already full implemented if developer just follow that path. No 'real' tool needed, even less a language. More so, language extensions or preprocessing scripts can handle the requirement independant of a certain language.

Every language that can pass function pointers can do so.

Last but not least, the basic idea is something that was used in software development for a long time. Handing over function pointer, nowadays called 'callbacks' are anything but new. Like in data base application were a search function could be called and get a filter handed.

Or standard screen handler that got called with a screen definition and, depending on the job a wariable number of call backs to read data, check data or write data back into the data base. Sounds much like your case, doesn't it? Programmign wise would that be handled by pseudo code (Macros) to be interpreted at compiletime inserting all necessary unctions.

Then again, you already mentioned that there is a huge gray area between inserting a pointer and a dedicated language construct, which is al well defined to be made for the purpose as deign pattern. If you want a reliable answer, on tools and/or languages, the topic does need a better definition how to meet your criteria.

  • The original question has several key words and phrases that limit the range of acceptable answers. I would agree that pretending the question is not precise makes the question problematic. But it is fairly (though, not perfectly) precise. – Brian H Apr 17 at 20:39
  • 2
    @BrianH While the question uses a lot of words to try to do this, technically you can do this in a powerful enough assembly language (TASM, MASM, LLVM, etc.). You have to build the abstraction yourself, but you can then write code using that abstraction. To be pedantic, Raffzahn wasn't right in saying that every language that can pass function pointers can do this; but the vast, vast majority that have function pointers do support enough other features to make the implementation of this design pattern possible. (Though the answer isn't v.helpful.) Does this help to narrow down your question? – wizzwizz4 Apr 18 at 10:10
  • @wizzwizz4 Several lessons about this site's dysfunctional nature can be gleaned by reviewing the FULL TEXT of the question, comments, and accepted answer, which was posted within 1 hr of the question. – Brian H Apr 18 at 14:12
  • @BrianH If you write something like "what language compilers had explicit support for" and clarify what you're asking for, I don't see why it can't be re-opened. Closing isn't a punishment nor a final state; it's merely to allow the question to be revised without encouraging answers like Raffzahn's here (no blame assigned). – wizzwizz4 Apr 18 at 15:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.