Knowledge Point catalogue ==========> Portal
What is abstract class first?
Abstract class is called abstract class by the keyword abstraction, abstract class is the natural role is inherited, so can not be instantiated, can only be inherited. And the abstract keyword cannot be used with sealed, because sealed is not allowed to inherit, so that is the meaning of the abstract class conflict.
Public Abstract class Test { }
Now that we know what the abstract class looks like, here's what the abstract class is for. As the name implies, abstract the objects common to the object. For example, cats and dogs and birds have eyes, all have mouths. Then we can abstract out an animal class. Put your eyes and your mouth in these public parts and abstract them into the animal class. Used to constrain subclasses that inherit from the animal class. Next time there's a dog. As long as it inherits from the animal class then the dog must realize the eyes and mouth.
The dog class inherits the animal abstraction. Vs suggests that we don't have two methods to implement the abstract class animal class. It can be seen that abstract classes are the constraints of a child class. Plainly. An abstract class is an abstraction of a subclass that extracts the public part of a child class and puts it into a particular class. An abstract class is a contract that provides constraints for a subclass of the same type (where the type is not a data type, but a logical division, such as a human and a cat are animals). To constrain their public parts.
Now let's summarize the abstract class.
1. The definition of abstract class requires the abstract keyword
2. The meaning of the existence of abstract classes is inherited. So it cannot be instantiated and cannot be used with the sealed keyword.
3. Abstract classes allow the existence of non-abstract methods and abstract methods.
4. Abstract members of abstract classes, subclasses must be implemented.
There are many concepts like interfaces, interfaces, and abstract classes. The interface is created to use interface, and the meaning of the interface appears to be inherited. And not with the sealed keyword.
Public Interface Animal { void Run (); void Say (); }
Interfaces are the same as abstract classes, and are abstract public ones.
Logically distinguished from abstract classes. summed up into a sentence. Is the behavior of the interface constraint subclass object. Abstract classes are the common parts of the same type class that are extracted and constrained. Note that the same type here is not data type but logical, such as people and cats, dogs are animals.
To summarize the difference between the two
1. C # has learned that classes can only be inherited, and interfaces can inherit more. This is the first difference between an abstract class and an interface.
2. An interface cannot contain an already implemented member, but an abstract class is possible
3. The member of the interface the default 1 implementation is public, but members of the abstract class can be accessed by the adornment adornment but cannot be private.
4. Abstract classes are used to constrain the core base members of an object, and the interface is used to constrain the behavior of subclasses. For example, what is the behavior of the type (method).
5. If the interface member changes, the realization subclass all must change, abstract only the abstract member changes the subclass to change.
6. Interfaces do not allow the definition of fields, abstractions allow the definition of fields, but do not allow the definition of abstract fields.
The most essential of the two words
abstract classes and interfaces are constraints that allow our code to have a better hierarchy, especially in the case of multi-person co-development (if everyone follows their own habits, development costs are not known to increase for the entire development team).
An abstract class is an abstraction (constraint) of the common part of a subclass of the same type (not a data type), and an interface is a constraint on the ability
Refer to Daniel's blog------> Portal
7.c# Knowledge Points: An introduction to abstract classes and interfaces