Difference between interfaces and classes

xiaoxiao2021-03-06  61

Depressed, one is submitted to submit a "relying on ', actually succeeded, fire big A re-translated, as a warmxing from Delphi Help, Keyword Interface Types: overview

Like the class, only the outermost layer of the program or unit is declared (i.e., INTERFACE Section, is globally visible), and cannot be declared in the process or function. The declaration format of the interface type is as follows: type interface [{guid} '] // The global unique identifier MEMBERLIST // member list END; ANCESTORINTERFACE and [' {Guid} ' ] Is an optional, interface declaration, and class, but there is a constraint: 1. MemberList can only contain methods and properties. Fields are not allowed in the interface. 2. Because the interface is not field, the property's read and write must be a method. 3. Members of all interfaces are public. Visibility specifies (private, protected, etc.) and storage designation (such as stiled, default, nodefault) is not allowed. (However, an array property can with keyword default, see the end of the description) 4, the interface does not have a constructor and a destructor. It cannot be instantiated, in addition to the way to implement it. 5. The method cannot be declared as Virtual, Dynamic, Abstract or Override. Because the interface does not implement its own method, these designation is meaningless. See an example of an interface statement: type imiqueoc = interface (ieterface) ['{00000002-0000-0000-C000-000000000046}'] Function Alloc (size: integer): Pointer; stdcall; function realloc (p: Pointer; size : Integer): Pointer; stdcall; procedure Free (P: Pointer); stdcall; function GetSize (P: Pointer): Integer; stdcall; function DidAlloc (P: Pointer): Integer; stdcall; procedure HeapMinimize; stdcall; end; in In some interface declarations, keyword interface is replaced by Dispinterface. The answer is that this (and DISPID, Read Only, Write Only) and special platform are related to Linux programming. There are also some insights other than helping: Interfaces are also used to solve the chaos caused by multiple inheritance. One derived class in Delphi can only inherit a class, but at the same time, it can inherit multiple interfaces. PS: About the interpretation of the array attribute, also from Delphi Help, Keyword Array Properties, please read the example: Property strings [index: integer]: string ...; default; this can we use object [index] to replace Object .property [index]; but also to pay attention, like this attribute can only exist, otherwise everyone knows what will happen.

转载请注明原文地址:https://www.9cbs.com/read-85952.html

New Post(0)