1

I just want to know whether the following question will be a good fit for this site.

Question Starts :

Quoting from Wikipedia :

"The advantage of interface injection is that dependencies can be completely ignorant of their clients yet can still receive a reference to a new client and, using it, send a reference-to-self back to the client. In this way, the dependencies become injectors "

I wish to understand each part of what is said there.

Let me put the example here from the mentioned source:

    // Service setter interface.
    public interface ServiceSetter {
        public void setService(Service service);
    }

    // Client class
    public class Client implements ServiceSetter {
        // Internal reference to the service used by this client.
        private Service service;

        // Set the service that this client is to use.
        @Override
        public void setService(Service service) {
            this.service = service;
        }
}

Now let me split the quotation in parts and try to explain them :

part1 : "..dependencies can be completely ignorant of their clients.." - quite understandable

part2: "..dependencies can be completely ignorant of their clients yet can still receive a reference to a new client and, using .. " - bold part is obscure. Q1) Client gets a reference to the dependency not the vice versa, right ?

part3: "..can still receive a reference to a new client and, using it, send a reference-to-self back to the client..." - quite understandable

part4: ".. In this way, the dependencies become injectors.."- bold part is obscure. Q2) Dependencies are being injected. So how can they themselves be injectors ?

Q3) Dependency is obviously injected in the example. Can we say that interface is also being injected only to enable the injection of the dependency in the example ?

Question ends.

||||||
3

I think your question is perfectly justified, when I read that part first, I was just as puzzled as you about what the Wikipedia author meant. After reading it 3 times, I think got it now, and if you ask it as a question, I would probably write an answer. (Hint: if you think of "dependency" not just as the Service class itself, but as a library which contains that class and additional infrastructure code, then part 2 & part 4 may start to make sense).

IMHO it looks like a good question for our site, it is focussed, it is about a topic (DI) which is discussed here on this site very often, and it is most probably not a duplicate of an existing question. It also shows the effort you invested to answer the question by yourself.

However, I can speak only for myself, some people in the community seem to downvote and close everything which smells a little bit like a request for discussion. They may mistake it for a "discuss this blog" type question. I don't share that point of view, since I think the question is perfectly answerable. The only way to find out is probably to ask and see what happens,

||||||

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .