Interfaceand an Abstract ClassProgram.cs ← Example Answer Not Included ❗An interface can be understood as a Contract for what a Repo is able to do.
In other words - ThisInterface holds the methods for what a repois able “to do”
An Interface does not hold any logic, just a list of the methods ← Contract
An interface file is created and holds the methods to whichever repo/class is relevant. The interface is then instantiated in your console app. Example code for instantiating your interface:
// instantiating the interface for the animal repo and service
IAnimalRepo animalServiceInterface = new AnimalRepo();
AnimalService animalService = new AnimalService(animalRepo);
Example answer:
Create a new method in your interface and then in your repo ← the newly created method NEEDS to be implemented in both your interfaceand your repo . This is related to question 1 where we explain that the interface is seen as a contract to what we promise this repo can do
// Interface
void GetUserByEmail(string email);
// Repo
public void GetUserByEmail(string email)
{
var user = _users.FirstOrDefault(u => u.Email == email);
if (user != null)
{
Console.WriteLine($"User found: {user.Name}, {user.PhoneNumber}, {user.Email}, {user.Type}");
}
else
{
Console.WriteLine("User not found.");
}
}