C # abstract class Interface introduction

1, Basic Concepts

Abstract class:

 1. abstract method only make a statement, and does not include implementation, can be seen as a virtual method does not achieve the body
 2. An abstract class can not be abstract, but abstract properties and methods, but once you have an abstract method, you must make the abstract class declaration is
 3. DETAILED derived class must override the abstract base class
 4. abstract derived class can override an abstract base class, may not be covered. If you do not cover, its concrete derived classes must override them.
 The abstract class can not be instantiated

interface:

 1. The interface can not be instantiated
 2. Interface method declarations can contain
 member 3. The interface include methods, properties, indexers, events
 4. Interface not contain constant field (domain), constructors, destructors, static member.
 5. All members of the default interfaces to public, and therefore the interface can not have the private modifier
 6. All members of the derived class must implement the interface
 7. A class can implement multiple interfaces directly with the interface between the comma
 8. a interface can have multiple parent interfaces, the interface implementation class must implement all the members of all parent interface.

Same point:

 1, can be inherited
 2, not be instantiated
 3, method declarations can contain
 4, the derived class must be implemented method is not implemented

the difference:

 1, abstract base class defines fields, properties, methods. Interface can only define the properties, indexers, events, and method declarations can not contain fields.
 2, multiple interfaces can be achieved, can only be a single abstract class inheritance

 3, abstract class is an incomplete class, the need for better (inheritance, and implementation). Interface specification is a behavior can be inherited directly reference

 4, the interface does not have the inherited basic features only be able to call it.

 5, the interface can be used to support the callback, but does not have to inherit this feature .
 
If the abstract class implements the interface, the interface can be mapped to the abstract methods as abstract classes without having to implement a method, the implementation of the interface method in a subclass of abstract class

 

aims select
Create multiple versions of assemblies
Abstract class
Small blocks and concise design features
interface
Large design functional unit
 Abstract class

 

 

 

 

 

 

 

2, abstract class interface and usage scenarios

1, first of all to understand what an abstract class. In object-oriented concept, we know that all objects are depicted by the class, if a class does not contain enough information to describe a specific target, such a class is an abstract class. An abstract class is often used to characterize the problem areas of our analysis, design abstraction drawn, is a series of looks different, but the same concept of the specific nature of abstraction. For example, we xpads project transaction class can be understood as an abstract class, spot transactions, forward transactions, swaps and other specific types of transactions are inherited class. Spot transactions, forward transactions, swaps these particular concepts are real, but the concept of trading in the field in question do not exist, it can be understood as an abstract concept. It is because there is nothing in the art abstraction corresponding with it practical problems, it is an abstract class for abstract concepts can not be characterized instantiated.

2, then understand how the interface, the interface is object-oriented design of a set of specifications, is a set of assembly process (also defines constants), the software design advocated in some modes oriented programming interface, in fact, to achieve shielding class internal processing, enhanced security module, flexibility, software design to achieve high cohesion, loose coupling.

3, an abstract class with the same characteristics and application behavior, can be implemented method, multiplexing can be achieved, the more the interface is a behavior definition, there can be achieved members.

 

 

 

Guess you like

Origin www.cnblogs.com/zjtao/p/11345366.html