Simple questions to test understanding of Dependency Inversion Principle

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

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.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật