Reputation: 5265
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
}
}
Upvotes: 6
Views: 1616
Reputation: 663
To make a long answer short: yes, this is an example of a Dependency Inversion Principle
Upvotes: 6