Implementation of the interface
Purpose of the interface:
An interface is a contract, which is a collection of method declarations that encapsulates the behavior (methods) common to some classes.
That is, when you define a method, only the parameter part is written to the end of the semicolon, and there must be some class to implement the interface to make sense.
The implementation of the interface, is in the class in turn the interface in the method of all write complete, that is, each complement the method body (curly braces and the code part inside).
The class that implements the interface can treat it as a subclass of the interface, and the interface can be thought of as their parent class. This can also expand the polymorphic, Richter replacement of the application.
1. What does the interface look like?
Very simple, the general interface is named after the capital letter "I", such as: IComparable, ICar.
2. How do I declare an interface?
Such a format:
Access modifier INTERFAC Interface Name {Some methods of declaration, but do not write the method body, after the parentheses directly followed by a semicolon on the line}
In this volleyball scoring program, most of us can use the system's custom interface
But some interfaces need to be defined by ourselves.
Usingsystem;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using Team.Models.Entities;
namespaceteam.models.interfaces
{
public interface Icategoryservice
{
void Ball (CategoryInfo category);
void Jiafen (int id);
void Jianfen (int id);
categoryinfo GetDetail (int id);
list<categoryinfo> GetAll ();
}
}
Knowing all of this is basically enough, and my early notes:
Interfaces are declared like classes, where members can contain signatures of methods (implicit public and abstract), properties, events, and delegates.
However, you cannot define data members (fields) and static members in an interface.
Unlike classes, interfaces are simply their declarations and do not provide implementations. The interface is therefore a collection of function declarations.
If a class or struct derives from an interface, the class or struct is responsible for implementing all the members declared in that interface.
An interface can inherit from multiple interfaces, and a class or struct can implement multiple interfaces.
Interfaces can be defined to be written out of the class, without being written together with the declarations of method fields in the class.
The implementation of the volleyball scoring (vi) interface in MVC development