Chapter 4. Automated Dependency Injection
You may well have heard of Dependency Injection—there’s a certain buzz around the term that has been moving through the ActionScript community for the last couple of years. It’s one of those terms that sounds like it must be really sophisticated and complex, but actually turns out to be a fancy name for a simple concept that you already understand how to use.
This doesn’t mean that it’s not powerful and interesting, but, as with most design patterns, it’s the neat capturing of an idea that many programmers encounter on their own into a single specific term—‘Dependency Injection’—that is most useful. You were probably already doing it; now you’ll have a more pithy way of referring to it.
So, what exactly is Automated Dependency Injection?
First of all, it’s worth knowing that Dependency Injection—also known as DI—is a complicated name for something you’ve been doing since the first time you passed a parameter to a function.
A dependency is just a requirement to use another object
If the UserXMLLoader class needs to be passed a
loadScriptPath:String of the url from
which to load its data, this is a dependency:
public function UserXMLLoader( loadScriptPath:String )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access