
界面是一个契约: 编写界面的人说: “嘿,我接受这种事情接口抽象类,使用界面的人说”. 好吧,我编写的过程看起来像这样. “
接口是一个空壳. ..只有方法的签名,这意味着该方法没有主体. 该界面无能为力. 只是模特.

例如(伪代码):
// I say all motor vehicles should look like this:interface MotorVehicle{
void run();
int getFuel();}// My team mate complies and writes vehicle looking that wayclass Car implements MotorVehicle{
int fuel;
void run()
{
print("Wrroooooooom");
}
int getFuel()
{
return this.fuel;
}}

实现接口消耗的CPU很少,因为它不是一个类,而只是一堆名称,因此没有昂贵的查找. 重要时接口抽象类,它很棒,例如在嵌入式设备中.
与接口不同,抽象类是类. 它们的使用成本更高,因为在继承它们时需要找到它们.

抽象类看起来很像接口,但是它们还有更多的东西: 您可以为它们定义一个行为. 超过一个人说: “这些类应该是这样的,它们有一些共同点,所以请填空!”
示例:

// I say all motor vehicles should look like this:abstract class MotorVehicle{
int fuel;
// They ALL have fuel, so lets implement this for everybody.
int getFuel()
{
return this.fuel;
}
// That can be very different, force them to provide their
// own implementation.
abstract void run();}// My teammate complies and writes vehicle looking that wayclass Car extends MotorVehicle{
void run()
{
print("Wrroooooooom");
}}
尽管抽象类和接口应该是不同的概念,但实现有时会使该语句不正确. 有时,它们甚至没有您想像的那样.
在Java中,此规则功能强大,而在PHP中,该接口是抽象类,没有声明任何方法.
在Python中,抽象类更像是从ABC模块获得的编程技能. 实际上,使用了元类,因此它们也是类. 用这种语言,该接口与鸭子类型更多相关,它是调用描述符的约定与特殊方法(_Method_Method)的混合体.
像编程一样,还有另一种语言的理论,实践和实践: -)
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-191895-1.html
小日本真正的经验
定位明确
不要一天都在自己近海训练