Jaime
Jaime
CC#
Created by krixsick on 7/12/2023 in #help
❔ Interfaces, IEnumerator and IEnumerable
That's noting, bro. I happy you can see clearly now. I will find lots of implementations with Interfaces.
35 replies
CC#
Created by krixsick on 7/12/2023 in #help
❔ Interfaces, IEnumerator and IEnumerable
Well, It doesn't make sense if you are not defining the same method in multiple classes. Anyway, it's a good practice to define certain type of methods using interfaces. Just in case you want to implement it in another class in the future. And also keep in mind that the definition of the method that the interface sets is required in the class that implements it. As I said I can be sure that all classes that implement the IMathOperations interface have a definition for the method sum()..
35 replies
CC#
Created by krixsick on 7/12/2023 in #help
❔ Interfaces, IEnumerator and IEnumerable
I would like to share my own explanation of why Interfaces are useful. Interfaces allows you define the signature of methods and property. When I say define the signature I mean that you only set the method's name and parameters. For example:
public interface IMathOperations {
int sum(int aNumber, int anotherNumber);
}
public interface IMathOperations {
int sum(int aNumber, int anotherNumber);
}
There is my IMathOperations interface (Note that the name starts with I it's a naming convection). My interface could now be implemented by any class. And any class that implements my interface will have to define what the sum() method does. So, what all this means is that I might have a bunch of classes implementing the IMathOperations interface, and I can be sure that all of them have the method sum(). That's clean code. It will help when you are coding using the IDE intelligence.
35 replies