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 8422709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:31:54+00:00 2026-06-10T03:31:54+00:00

I recently read about the Dependency-Inversion Principal in Robert.C.Martin’s excellent book Agile Principals, Patterns

  • 0

I recently read about the Dependency-Inversion Principal in Robert.C.Martin’s excellent book Agile Principals, Patterns and Practices in C#. However there is one aspect of this principal that I feel I don’t fully understand.

Robert explains that when high-level modules depend on lower level modules, changes in the lower level modules can cause the higher-level modules to change also. He demonstrates this with the following example:

public class Button
{
   private Lamp lamp;
   public void Poll(){
      if(/*some condition*/)
         Lamp.TurnOn();
   }
}

About this code Robert says “The Button class depends directly on Lamp class. This dependency implies that Button will be affected by changes to Lamp.”

As I see it there are two possible kinds of change that we might make to the Lamp class:

1) We may want to change the internal implementation of the class but without affecting the public interface.

2) We may decide to change the public interface to say pass a parameter to the TurnOn method.

What I don’t understand is that in the first case why would our changes cause a change to the Button class? The public interface to Lamp has not changed so why would Button need to change?

In the second case I can see that this would require us to change Button. But in this case how would depending on an abstraction change this? Surely if I have a valid reason to change the interface to Lamp then I would also be changing the interface in the abstraction that Lamp and Button depend on. In this case then I have to change Button anyway as the abstraction it depends on has changed.

I realise that there are other benefits to DIP such as re-usability of higher level modules, ownership of interfaces by higher level modules and ability to choose implementations of dependencies at runtime, however I’m struggling to understand how DIP reduces the need for depending modules to change when the interface to a lower level module changes and/or why internal changes in a dependant module may cause change in higher level modules.

  • 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-06-10T03:31:55+00:00Added an answer on June 10, 2026 at 3:31 am

    I believe the important difference that DIP brings into this example is ownership of the interface. Particularly which layer owns the interface, where the Button is the client and the Lamp is the server.

    In the dependency to the concrete class Lamp, the interface (.TurnOn()) is owned by the Lamp class (server). Therefore a decision can be made to change the .TurnOn() method based solely on the needs of the server as it owns the method, and this will require a subsequent change to the Button class (client).

    When the interface is abstracted to an ISwitchableDevice Interface/Abstract class, the ownership is transfered to the client or a shared layer. Therefore a change to the interface cannot be driven directly by servers needs, any changes to the Lamp class (owned by the server) can be made without changing the interface. And if changes to the ISwitchableDevice Interface are required then this will be driven by the needs of the client or shared layer.

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

Sidebar

Related Questions

Recently I have read about hash-tables in a very famous book Introduction to Algorithms
I recently read a jQuery tutorial about best practices. I usually run all my
I have recently read topics about memory fragmentation: How to solve Memory Fragmentation and
I recently read an article about password hashing . How are MD5 or SHA1
I recently read an article about c#-5 and new & nice asynchronous programming features
I recently read a post about no longer needing to declare ivars as well
I recently read a post online about rotating text with css. This appealed to
I've read about Single-Page Applications recently and wanted to try one out. After watching
I have read about the push technologies recently. Using it real-time data streaming is
I've recently heard about Qt and read about how fun it is to develop

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.