Junior OOP

What is the Dependency Inversion Principle and how do interfaces support it?

  • High-level modules should not depend on low-level modules. Both should depend

on abstractions.

  • Interfaces allow decoupling and easier testing.

interface ILogger { void Log(string message); }

class FileLogger : ILogger { public void Log(string message) =>

Console.WriteLine("File: " + message); }

class UserService

private readonly ILogger _logger;

public UserService(ILogger logger) { _logger = logger; }

More from C# Programming Tutorial

All questions for this course