Home > Back-end >  Classes and interfaces
Classes and interfaces

Time:09-17


The unit Unit3.

Interface

USES the SysUtils;

Type
CarMove=interface
The function SpeedDown () : string;//deceleration
The function ShutDown () : string;//stop
The function Start () : string;//start
The function carspeedUp () : string;
The function StartBrake: string;//start braking
end;

{parent class: car class}
Tcar=class (TObject)
Private
Name: string;
Fwheel: Twheel;
Fbrake: Tbrake;
Fengine: Tengine;
Fcarbody: Tcarbody;
Public
The function CarPackage (s: string) : string; Virtual;//assemble car
end;

TAodiQ7=class (TCar, carMove)
Private
Protected
//interface carMove
The function SpeedDown () : string;//deceleration
The function ShutDown () : string;//stop
The function Start () : string;//start
The function carspeedUp () : string;
The function StartBrake: string;//start braking
Public
The function CarPackage (s: string) : string; Override.
end;

Implementation

{TAodiQ7}

The function TAodiQ7. CarPackage (s: string) : string;
The begin

end;

The function TAodiQ7. CarspeedUp: string;
The begin

end;

The function TAodiQ7. ShutDown: string;
The begin

end;

The function TAodiQ7. SpeedDown: string;
The begin

end;

The function TAodiQ7. Start: string;
The begin

end;

The function TAodiQ7. StartBrake: string;
The begin

end;

{Tcar}

The function Tcar. CarPackage (s: string) : string;
The begin

end;

End.



Interface carMove statement SpeedDown ShutDown () () the Start () carspeedUp () StartBrake these functions and methods in subclasses TAodiQ7 to reiterate again, since I don't understand is why at the interface and restated declaration is not reinvent the wheel, please don't take no points

CodePudding user response:

Interface was a behavior, only regulations only, by calling the class to implement interface, baidu about the definition of interfaces and classes,,,

CodePudding user response:

reference 1st floor a295281315 response:
interface just rules behavior, just only require, by calling the class to implement interface, baidu about the definition of interfaces and classes,,,
that I don't can also realize, why bother

CodePudding user response:

TAodiQ7 is the interface implementation class, this is not a class inheritance, do not use such way of thinking, interface can be multiple inheritance, but delohi can not multiple inheritance, why use interface, this is not to explain in a few words, can simply understand the higher level of abstraction of the interface, as to when to use interface no time in class, can only slowly appreciate, feels but not talk

CodePudding user response:

refer to the second floor u011653354 response:
Quote: refer to 1st floor a295281315 response:

Interface was a behavior, only regulations only, by calling the class to implement interface, baidu about the definition of interfaces and classes,,,
that I don't can also realize, why bother?


Don't is possible, may call interface implementation class has a lot of, the car is the audi, BMW and Mercedes, but they have started to stop the brake behavior, the behavior into abstract interface, the new model class again, you can directly inherited this interface, standardization of new models of behavior (call start stop brake not call audi start 123 BMW call start 345).

CodePudding user response:

Like word is one part of a letter, audi is the class inheritance, interfaces and base classes, define a total of behavior into the interface, the with common attributes, method is defined as a class, then they combine to generate concrete classes (audi, BMW, mercedes-benz class),
These concepts are abstract, speak bad

CodePudding user response:

Are Delphi VCL architecture using inheritance/basic is completely can entrust this structure covers the concept of "interface", but "interface" is essentially a Windows system, which is the most effective tools For Microsoft, since you want to develop applications For Windows, that, of course, to compromise,

CodePudding user response:

Has little to do with Windows, although the initial interface appears is to simplify the program design based on COM (in D5, is the most basic interface IUnknown, is clearly related to COM), but from the beginning of the D6, has become the basic interface IInterface, is a basic language features,

CodePudding user response:

In fact I think a295281315 already speak clearly, these functions declared in the parent class or property, saying only that it has these, again in a subclass, the statement is a specific description of
Can understand so, car has a steering wheel, so in class car I want to declare a steering wheel, for audi, it also has the steering wheel, so I have to declare a steering wheel in the audi, because audi steering wheel and the car steering wheel is the same thing, so audi classes inherit from the car steering wheel, Honda also can inherit the steering wheel, and can give their own steering wheel add some functions or attributes of individuation, audi personalized part of the steering wheel, the car of this class is not in the steering wheel,
If the class does not declare the steering wheel, that is to say, car is this kind of steering wheel, so an audi will define the steering wheel, Honda also want to define your own steering wheel, each car to define your own steering wheel, although for each car, no impact, but for this kind of cars, there is no steering wheel, and the future, if we need to describe "through the steering wheel can control the direction of travel car", cannot be done,

CodePudding user response:

Actually interface just opened a hole of an object, the cut contains you can to the caller (client) to visit some of the methods or properties

CodePudding user response:

refer to 7th floor DelphiGuy response:
has little to do with Windows, although initial interface appears is to simplify the program design based on COM (in D5, is the most basic interface IUnknown, is obviously related to COM), but from the beginning of the D6, has become the basic interface IInterface, is a basic language features,

COM is Microsoft original controls for Visual Basic 3.0 specification, if from the point of view of efficiency, COM is slag was not the VCL seconds left, but, after all, Microsoft took control of the foundation platform, so they have a DCOM out fool bai

CodePudding user response:

Personal understanding, interface definition is a description of class function expansion, the inheritance of class, there is no specific implementation methods, therefore, not override keywords, but inherit the interface class must implement the interface methods (even if only a pair of the begin end), therefore, must be behind the statement again; When a Class to be inherited, can have a variety of interface, generate new classes are different, of course can also be no interface, so just to give Class to change a name, or by overriding the superclass method, based on the original Class to strengthen the function and generate new classes, like Form1=Class (TForm) is a Class without interface inheritance; Another understanding is that the interface is also a class, is an abstract class, there is no ready-made implementation method (unlike a real class, already with implementation method), just gave a name to you, how do you achieve your skill, inheritance is only two classes packaged into a class with more functions, be inherited interface and should be inherited classes do not have what big relationship, with continued its class has a lot to do,

CodePudding user response:

Interface to the client is called let it follow your specification, the specific server can be done according to the specific circumstances of different implementations, such easy to call with the same specification, the so-called remove coupling

CodePudding user response:

nullnullnullnullnullnullnull
  • Related