We often discuss the similarities and differences between interfaces and abstractions in our daily work. Next I will discuss this issue with you to use it as an example. I hope you will get a lot of jade.
Interfaces are very similar to abstract classes, including implementation and inheritance of their own classes to implement all method attributes. As mentioned in the implementation of the preceding interface, we can declare istorable as an abstract class:
// Define an abstract class
Abstract class stroable
{
Abstract Public void read ();
Abstract Public void write ();
}
// Define the interface
Interface istorable
{
Void read ();
Void write (Object OBJ );
Int status {Get; set ;}
}
Document inherits from istrobale, which is similar to the implemented interface.
The interface can be inherited multiple times, and the abstract class cannot. Abstract classes should be considered only when method definitions or member variables must be used.
According to the collected technical standards, Microsoft designers generally do not recommend that you use interfaces. Instead, they recommend the use of abstract classes, because abstract classes facilitate version control. Suppose you have designed an interface for programmers to use. Now you want to add a new member to this interface. At this time, you have to change the existing interface and destroy writing new code for the original interface, or create an interface like istrobale2. If you do this frequently, you will soon get a large number of closely related interfaces, resulting in more and more complex systems.
To use an abstract class, you just need to append a new virtual method and configure it to be implemented by default. This can solve the problem, no new classes are introduced in the same namespace.
The best practice is: to create a class library that has been reused by many people, it is best to use abstract classes. To create a class for a single project, it is better to use interfaces, this is because the interfaces have elasticity that is easier to understand than abstract classes.