I am preparing a short (1-2 hour) presentation about DIP to several (~5) junior developers (1-3 yr xp) in the office. At the end of the presentation I want to know whether they understood what I was presenting, what are some possible questions that I ask in order to figure out their understanding? Maybe something that can be answered and explained by them in 3 minutes or less?


With regard to patterns, I often find myself in the situation that I don't fully understand and much less appreciate the pattern until I can explain why it is a better solution than a different pattern/style in a given situation.

Therefore, I would present examples that precisely don't use dependency injection and let the audience point out concrete difficulties that these code snippets have (with regard to modularity, testability), etc.

As a concrete example, show code of the kind:

def sendMessage(msg):
  if len(msg) > 160:
    raise MessageTooLongException('message is longer than 160 chars')
  with TweetService() as tweetService: # needed to send the message
    tweetService.tweet(msg, API_KEY)

A good answer should point out that it is impossible to unit test this method without relying on Twitter's services:

Obviously, if Twitter is down, your unit test would fail because the tweet method raises an exception even though your code is fine. If we were using DI, we could provide a mock TweetService object which allows to check whether the tweet call was made and the object disposed of correctly.

Providing negative examples has the advantage that it trains your audience to recognize such code as they write it and helps them to notice the benefits of DI in these situations right ahead.


I often try to transpose the principles of OOD/OOP into real-life situations, as OOP arose largely as a result of the need to infuse real-life models into programming. I don't think DI is missing from our everyday lives. Take the humble charger for example, pick anyone (except the iPhone charger). A large majority of manufacturers default to the micro-usb form factor for charging points. The advantages

  1. To the user, you can essentially use any charger with any mobile phone. Contrast this with the iPhone and the latest charging port debacle and the DI pretty much justifies itself

  2. To the manufacturer, a single production line can cater for all the charging unit needs of their entire product line.

If your students can adequately transpose the DI principle into real-life scenarios, IMO, it's a good reflection of their understanding of the principle

  • 2
    I don't recognize the DI principle in your example. What you describe are the advantages of having the same interface. In order to apply DI, you already need to have a common interface, the question is whether the instantiation of this interface should be done by the component requiring the object or whether it should be delivered from outside. – blubb Apr 24 '13 at 11:11
  • @blubb, the way I understand it, you dont necessarily need common interfaces to use DI (you can get away with not using an interface). I might have used a stronger example, but in my analogy, a production line for mobile phone chargers is DI context and the mobile phone the DI target. I'll use a better analogy – kolossus Apr 24 '13 at 16:49

You could concentrate your comprehension questions on the practical consequences of DIP principle.

DIP is about minimizing dependencies from implementations in order to achieve some quality goal, so you could possibly give two small designs, one with client's class dependency on an interface and one with direct dependency to the implementation.

Let your audience explain the advantages of using DIP with respect to different qualities, e.g. testability or maintainability.

  • Does this mean that they really understand it? For example, they might be just repeating the slides without really understanding it – Louis Rhys Apr 23 '13 at 8:19
  • depends on how extensive the slides are and how complex the example design is – McMannus Apr 23 '13 at 8:25
  • yup, that's why I ask the appropriate example design to be subject of the question. – Louis Rhys Apr 23 '13 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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