Junior — Middle
Have you dealt with implementing or applying interface constructs in your projects?
sobes.tech AI
Answer from AI
In C#, interfaces are used to define contracts that classes or structures must implement. This allows for creating flexible and extensible architectures.
Example of an interface and its implementation:
public interface ILogger
{
void Log(string message);
}
public class ConsoleLogger : ILogger
{
public void Log(string message)
{
Console.WriteLine(message);
}
}
This approach allows changing the logger implementation without modifying the code that uses it, which improves testability and maintainability.