Dependency Inversion Principle: High Level and Low Level module example
Asked Answered
D

1

6

I was going through the following link to understand what high-level and low-level modules mean in the context of Dependency Inversion Principle.

As per the explanation given there, is the following code snippet a good/appropriate example?

public class HighLevel
{
    private IAbstraction _abstraction;

    public HighLevel(IAbstraction abstraction)
    {
        _abstraction = abstraction;
    }

    public void Act()
    {
        _abstraction.DoSomething();
    }

}

public interface IAbstraction
{
    void DoSomething();
}

public class LowLevel: IAbstraction
{
    public void DoSomething()
    {
        //Do something
    }
}
Dromedary answered 25/4, 2017 at 6:46 Comment(0)
V
6

To make a long answer short: yes, this is an example of a Dependency Inversion Principle

Vagary answered 25/4, 2017 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.