interface inheritance和implementation inheritance的区别?

wdlius 2002-06-26 11:01:51
今天看C++Builder深度探险,有一句话讲道COM主张的是interface inheritance,而不是implementation inheritance.
不知道这两者有什么区别。
...全文
114 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ajoo 2002-06-29
  • 打赏
  • 举报
回复
Not only COM.
it's the principle of all OOP and OOD.
in OO language,
interface inheritance is also called subtyping.
implementation inheritance is also called subclassing.

subtyping gives loose coupling, flexibility.
subclassing gives tight coupling, more static.
look at the following pseudocode:

interface IA{
void f();
}
interface IB:IA{
void g();
}
class A1:IA{
...
}
class A2:IA{
...
}
class A3:IA{
...
}
NOTE, if we use subclassing to reuse code from A1/A2/A3, then:
class B1:A1, IB{
void g(){...}
}
class B2:A2, IB{
void g(){...}
}
...

see? when you do subclassing, you have to specify which specific implementation class (A1 or A2 or A3?) to inherit.


While if we use interface inheritance:
class B:IB{
void f(){a.f();}
void g(){...}
private final A a;
}

one class B can reuse any one of A1, A2 and A3.
bill_lasker 2002-06-29
  • 打赏
  • 举报
回复
interface inheritance:
接口继承,使得子类的接口与父类一致,即调用方式一致
implementation inheritance
实现继承,使得子类的动作与父类一致
hollysky 2002-06-28
  • 打赏
  • 举报
回复
virtual function map
kiko_lee 2002-06-27
  • 打赏
  • 举报
回复
呵呵,一个是接口继承,一个是执行继承。
一个是接口,一个是执行,不一样哦

1,268

社区成员

发帖
与我相关
我的任务
社区描述
软件工程/管理 管理版
社区管理员
  • 研发管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧