Programming

  1. Explain the differences between an Interfaceand an Abstract Class
  2. Describe how an interface can be implemented
  3. Show how you can expand an existing interface in your project and how classes that implement (inherit from) the interface must be adapted
  4. Show how you can test your code in your Program.cs ← Example Answer Not Included ❗

Question 1

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

Question 2

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);

Question 3

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.");
        }
    }

System Development

  1. How would you visualize the existence of an interface in your class diagram?
  2. How would you visualize the relation between the interface and the implemented class?
  3. Provide further examples of various relation types