Comparison of various language polymorphisms

xiaoxiao2021-03-06  137

Simplely organize related content of various language polymorphisms and some advanced features.

------------------------ Delphi -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - [Overload] add Overload

[Virtual foundation] Delphi does not support much inheritance, so there is no deficiencies.

[Virtual function] The false function definition of the parent class has two ways: (1) Procedure Draw; Virtual; (2) Procedure Draw; Dynamic; Basically, the former speed optimization, the latter capacity optimization.

Subclasses are covered with Override: Procedure Draw; Override;

[Pure virtual function] The parent class defines the following procedure fly (); Virtual; Abstract;

The subclasses are used as follows: procedure fly (); override;

[Abstract class] Do not know if Delphi does this concept, it seems that there is no mention.

[Interface] IFOO = Interface ['{2137BF60-AA33-11D0-A9BF-9A4537A42701}'] Function F1: Integer;

IBAR = Interface ['{2137BF61-AA333-11D0-A9BF-9A4537A42701}'] Function F1: interger;

[Property] TMYOBJECT = ClassPrivate: SomeValue: Integer; Procedure SetsomeValue (Avalue: Integer); public: Property value: Integer Read SomeValue Write setsomeValue;

Procedure TmyObject.setsomeValue (Avalue: Integer); Begin if SomeValue <> Avalue Then SomeValue: = AVALUE;

---------------------- C ---------------------- [Overload] definition The same name is different from the function, there is no special keyword.

[Frequent Bastronomy] When inheriting, use the Virtual keyword declaration inheritance mode to avoid multiple copies of the same class in the base class. Class A // Defines the base class a {a (int i) {} // base class constructor, there is a parameter ...}; Classb: Virtual public a // A is a virtual base class {b (int N): A (n) {} // class B structure function, in the initialization table initialization ...}; classc: Virtual public a // a viable base class {C (INT N): a (n): a (n) {} // Class C constructor, in the initialization table initialization ...}; classd: publicb, publicc // class D constructor, initialize {D (INT N) in the initialization table: A (n), b (n), c (n) {} ...} [virtual function] uses the virtual declaration function in the parent class and implements the definition of the function; overloading this function in the subclass, you can implement the dynamic joint Compile. The parent class contains virtual functions: Class Point {public: Point (double i, double j) {x = i; y = j;} Virtual double area () const {return 0.0;} private: double x, y;};

Subclass override the virtual function: Class Rectangle: Public Point {public: Rectangle (Double I, Double J, Double K, Double 1); Virtual Double Area () Const {Return W * h;} private: Double W, H; }

Call this function to achieve dynamic networking: void fun (point & s) {cout << S.Area () << endl;}

[Pure virtual function] Use the keyword Virtual declared function and does not implement the definition of functions. For example, two pure virtual functions are defined in the following classes, Class Point {public: Point (int i = 0, int J = 0) {x0 = i; y0 = j;} Virtual void set () = 0; Virtual Void Draw () = 0; protected: int X0, y0;

[Abstract class] It is called an abstract class with a pure virtual function that can only be used as a base class. The abstract class is a special class, which is established for the purpose of abstract and design. It is in the upper layer of inherited hierarchy. The abstract class cannot be defined. In practice, in practice, in practice, in order to emphasize a class is an abstract class, Describe the constructor of this class as the protection of access control permissions. Class Shape {public: Virtual float area () const {return 0.0;} Virtual float volume () const {return 0.0;} Virtual void shapeName () const = 0;

If the function in the child class is not overloaded, the subclass is also an abstract class.

[Interface] The form is to replace the Class in the abstract class to Interface, which can be inherited from other interfaces, of course, the most important class inheritance. As commonly used COM IUnknown interface following statement: interface IUnknown {virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void ** ppv) = 0; virtual ULONG STDMETHODCALLTYPE AddRef (void) = 0; virtual ULOND STDMETHODCALLTYPE Release (vod) = 0;} The interface is generally used in C to implement the interface. [Properties] There is no such thing in standard C .

----------------------------------------------- --- [Overload] Defines the function of the same name to the different entries, no special keyword, and C .

[Frequent base class] Do not prevail this inheritance.

[Virtual Function] Use the Virtual declaration function in the parent class and implement the definition of the function; public Virtual Bool SQLEXE (BOOL B) {Return True;} Overwrite this function with Override in the subclass, you can implement dynamic cable.

[Pure virtual function] Use the function of the keyword Abstract to declare the function and does not implement the definition of the function, must exist in the abstraction class. Public Abstract Bool f (); override this function with Override in the subclass.

[Abstract class] Declaration with Abstract, the parent class can include virtual function declarations, and the definition of the virtual function can only be used as the base class. Public Abstract Class Cl {Public CL () {} public abstract bool f ();

[Interface] and class definitions are similar, with Interface description. [attributes] [MODIFIERS] Interface Identifier [: Base-list] {interface-body} [;] 1, attributes: Additional definition information. 2, Modifiers: Allows the modifiers that are used with NEW and four access modifiers. They are: New, Public, Protected, Internal, Private. In an interface definition, the same modifier does not allow multiple times, the New modifier can only appear in the nested interface, indicating that the same name member of the inheritance comes. Public, Protected, Internal, and private modifiers define access to the interface. 3, indicators and events. 4, Identifier: Interface name. 5, base-list: Contains a list of one or more explicit base ports, and the interface is separated by a comma. 6, Interface-Body: Definition of the interface member. 7, the interface can be a member of the namespace or class, and can include the signature of the following members: method, attribute, indexer. 8, one interface can be inherited from one or more base ports. Allow multiple interfaces to be implemented

For example interface defines with events is as follows: public delegate void StringListEvent (IStringList sender); public interface IStringList {void Add (string s); int Count {get;} event StringListEvent Changed; string this [int index] {get; set; }

[Property] private int myheight;

Public int myheight {get {return this.myheight;} set {this.myHeight = value;}}

--------------------------------------------------------------------------------------------------------------------------- ---

[Overload] The function is different from the same name. [Virtual foundation] Single inheritance is not popular!

[Virtual function] Without this concept, Java automatically realizes the dynamic network, do not believe you try!

[Pure Virtual Function] Call an abstract function in Java, not a pure virtual function, must be defined inside the abstraction, and there is no method body. For example: Abstract Class demo {Abstract void method1 (); abstract void method2 (); ...}

[Abstract class] Abstract Class demo {Abstract void method1 (); abstract void method2 (); ...} [interface] knows that there is an abstract class, why do you want to interface? Because Java is single inheritance, but the interface can inherit multiple! Implement Most Design Mode Key Technologies: Interface Demo {Void Method1 (); void method2 (); ...} [final class] Final class cannot be inherited If you think a class definition is perfect, you don't need to regenerate it Class, then modify it into Final class classname {...}

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

New Post(0)