none
SOLID Design Principles : Liskov Substitution Principle and Dependency Inversion Principle RRS feed

  • Question

  • Hi there. Just a thought and a question to the Microsoft Development Community about the OO software design principles called SOLID. What is the difference between the Liskov Substitution Principle and the Dependency Inversion Principle please ? I have thought about this for a while and I'm not sure of the difference. Please could you let me know ? Any thoughts / feedback very welcome.

    Many thanks and best regards, Taher Hassan

    Monday, October 7, 2019 9:54 AM

All replies

  • Hi Taher,

    Sorry for delay in reply.

    According to your description, this issue is more related to SOLID Design Principles. Since our forum discusses the usage of tools and editors in Visual Studio IDE, we recommend you could redirect to stack overflow with tag solid-principles, and start a new thread with ‘solid-principles’ to seek for a more professional support.

    BTW, if you have any Visual Studio general questions in the future, feel free to contact us and we will try our best to help you.

    Thanks for your understanding and have a nice day.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 8, 2019 1:49 AM
  • Hi Taher Hassan,

    Sorry for bothering you.

    As far as I know, Liskov Substitution Principle and Dependency Inversion Principle are essentially different.

    Liskov Substitution Principle -- the child class inherites parent class, it could use non-abstract funtions, which from parent class, or expend other functions, but it could not overwirte non-abstract function which is from parent class, if you want to override it , the pre-conditions of the method (i.e. the formal parameters of the method) are more relaxed than the input parameters of the parent method, please refer this image:

    Dependency Inversion Principle -- It is about high level class(H) and low level class(L). H means to perform complex logical operations, L means to perform basic operation. Normally, H is directly dependent on L, when we modify the L, we also need to modify H, and it may affect the security of program. So the principle requires that we should create a virtue interface, H and L are directly dependent on it, then we can modify H and L at the same time without worrying about the security of the program. Please refer this image:

     

    In summary, the Liskov Substitution Principle is to protecting the inheritance system and Dependency Inversion Principle is to Reduces coupling between modules.

    Hope it could help you.

    Best Regards,

    Dylan





    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, October 10, 2019 8:57 AM