Is-a、has-a、Like-a区别

Is-a:

是a:A Is B:A是B(继承关系,继承)。

has-a:

有a:A has B:A有B(从属关系,聚合)。

like-a:

像a:A like B:A像B(组合关系,接口)。

关于Is-a、has-a、like-a的使用场景:

如果A,B是Is-a关系,那么应该使用继承,例:玻璃杯、塑料杯都是杯子。

如果A,B是has-a关系,那么应该是用聚合,例:汽车由发动机,底盘,车身,电气设备等组成,那么应该把发动机,底盘这些类聚合成汽车。

如果A,B是like-a关系,那么应该使用组合,例:空调继承于制冷机,但它同时有加热功能,那么你应该把让空调继承制冷机类,并实现加热接口。


抽象类与其派生类是一种“is-a”关系,即父类和派生子类在概念上的本质是相同的(父子关系,血缘联系,很亲密)。 

接口与其实现类是一种“like-a”关系,即接口与实现类的关系只是实现了定义的行为,并无本质上的联系(契约关系,很淡漠的利益关系)。

举个例子:比如说一个动物抽象类,定义了跑的方法、叫的方法,但如果一个汽车类可以实现跑、可以实现叫,它就可以继承动物抽象类吗?!这太不合理了,汽车不是动物呀!而如果通过接口定义跑的方法、叫的方法,汽车类作为实现类实现跑和叫,完全OK很合理,就因为没有继承关系的约束。


注:以上文章仅是个人学习过程总结,若有不当之处,望不吝赐教。

  • 19
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Title: Humanoid Robots. Human-like Machines Author(s): Hackel M. (ed.) Year: 2007 Edition: 1st edition Language: English Pages (biblio\tech): 652\652 ISBN: 978-3-902613-07-3 As the world at our time has to face developments like keen climate change and globalisation, one may ask about the significance of building human-like machines, which probably will never operate as effective as humans in their diversity of potentialities. The benefits from tumbling two-legged mechatronic creatures and multiprocessor-based question-and-answer games seem hard to discover for noninvolved persons. In general the benefits from fundamental research are not evident - and humanoid robotics research means fundamental research in the field of robotics. It is an enormous challenge for all humanoid researchers that evolution has originated such effective sensors, controllers and actuators. Building humanoid robots involves the development of lightweight and energy-saving actuators, fast and intelligent sensors and exceptional complex control systems. By merging these technologies we investigate the cooperation of complex sensor-actor systems as well as and human-machine interaction. In analogy to space research humanoid robotics research, driven by the goal to copy and serve the pride of creation, will have a strong impact in daily live products. In this book the variety of humanoid robotic research can be obtained. The first chapter deals with remarkable hardware developments, whereby complete humanoid robotic systems are as well described as partial solutions. In the second chapter diverse results around the biped motion of humanoid robots are presented. The autonomous, efficient and adaptive two-legged walking is one of the main challenge in humanoid robotics. The two-legged walking will enable humanoid robots to enter our environment without rearrangement. Developments in the field of visual sensors, data acquisition, processing and control are to be observed in third chapter.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值