Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7025259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:57:01+00:00 2026-05-27T23:57:01+00:00

I frequently get the term Dependency Injection in a AS3 book i am reading.

  • 0

I frequently get the term “Dependency Injection” in a AS3 book i am reading. However, it’s has not explained what exactly it is. May anyone pls exhibit what exactly it is using some lines of AS3.0 code ?

Thanks
Vishwas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:57:02+00:00Added an answer on May 27, 2026 at 11:57 pm

    Dependency Injection simply means that instead of a class deciding what objects it needs in order to work it gets passed those objects from outside.

    In normal development, our objects decide their classes concretely, like this:

    public class MyClass
    {
        private var m_someObj:SomeObj = null;
    
        public function MyClass()
        {
            this.m_someObj = new SomeObj;
        }
    }
    

    Moving to Dependency Injection, MyClass now gets its dependencies from external:

    public class MyClass
    {
        private var m_someObj:SomeObj = null;
    
        public function MyClass( obj:SomeObj ):void
        {
            this.m_someObj = obj;
        }
    }
    
    var myClass:MyClass = new MyClass( new SomeObj );
    

    In that example, we pass in the SomeObj class when constructing MyClass. You can also use public variables/properties either. Passing objects through the constructor is good for vital dependencies.

    Now to make this actually useful, we can use interfaces instead of concrete classes. This lets us change the behaviour of MyClass easily:

    public interface ISomeObj
    {
    }
    
    public class SomeObjImplA implements ISomeObj
    {
    }
    
    public class SomeObjImplB implements ISomeObj
    {
    }
    
    public class MyClass
    {
        private var m_someObj:ISomeObj = null;
    
        public function MyClass( obj:ISomeObj ):void
        {
            this.m_someObj = obj;
        }
    }
    
    var myClass1:MyClass = new MyClass( new SomeObjImplA );
    var myClass2:MyClass = new MyClass( new SomeObjImplB );
    

    To give you an example, the ISomeObj interface might describe a renderer. The SomeObjImplA class will render using the normal addChild() techniques, while the SomeObjImplB class will render using blitting. Now, you can change how you render your MyClass object simply by changing a parameter – the MyClass class doesn’t need to know if it’s being rendered normally or through blitting.

    The object that decides what class to pass to MyClass is what’s called an injector. How it decides which class to inject is where you get the flexibility. For example, you could load a XML object that contains the classes to inject, or use reflection, which is how Robotlegs works I think.

    The link that 32bitkid posted is a pretty good explanation of the principle, but that’s the gist of it. You can also check out the wiki page. For bonus points, read about Inversion of Control, which is somewhat related.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get frequently SQLiteDoneException, 06-29 02:03:34.816: WARN/System.err(30470): android.database.sqlite.SQLiteDoneException: not an error 06-29 02:03:34.816: WARN/System.err(30470):
When retrieving packages with Cabal, I frequently get errors with this message: user error
I am using Python's AWeber API (https://github.com/aweber/AWeber-API-Python-Library), and I frequently get these exceptions. I
I've got a method which gets called frequently by different treads. Sometimes I get
I am trying to get the most occurring term frequencies for every particular document
I frequently get what appears to be a stackoverflow error ;-) from YUICompressor. The
I frequently get this error (it is so annoying!): Error report: ORA-06502: PL/SQL: numeric
When logging in Go with log.Println , I frequently get 2012/05/13 16:45:50 evaluating %v(PANIC=3)
In Silverlight, a frequently used pattern is: Request data Get back an empty container
I frequently get an app crash while the ListView is calling on the Adapter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.