什么是is-a和has-a关系
he is a people
he has a head
我是一个男人 is-a
我有一个女人 has-a
is_a 用于继承
has_a 是组合 一个类中包含了其他类
一般我们认为继承可以分为两种基本的形式:实现继承和接口继承。
实现继承的主要目标是代码重用:
我们发现类B和类C存在同样的代码,因此我们设计了一个类A,用于存放通用的代码。
基于这种思路的继承称为实现继承。
接口继承不同,它是基于现实生活中的语义的,表现了IsA的关系:
我们认为存款帐户和结算帐户都是帐户的子类,这种继承我们称之为接口继承。
注意,有些文章中一个类实现一个接口的行为定义为接口继承,这和这里的接口继承是不同的概念,为了区分两种概念,我们可以使用接口继承的另一种称呼-类型继承。
继承的关键就在于如何灵活的运用两种继承方式。
这里的接口的意思和Java或者C#中的interface有着不同。
在此的接口表示的是一个类中所有公有的方法的签名。
所以IsA关系是关于行为的。
HasA关系,也称为对象组合。实际上,HasA关系有两种。
第一种,静态HasA关系。这在UML中叫做组合(composition),比如“汽车has-a引擎”。
此种关系很像聚集,除了‘部分’的生命周期由‘整体’控制。
这种控制可能是直接的或者传递的。即‘整体’可能对创建或者销毁‘部分’具有直接的职责,或者它可能获得已经创建的部分,稍后传递给其它的假定对其有职责的整体。
第二种,动态HasA关系。这在UML中叫做聚合(aggregation),比如“飞机场has-a飞机”。
别忘了use-a 是依赖关系
相关推荐
03-11_面向对象与is-a_has-a_7题定义.pdf
03-11_面向对象与is-a_has-a_7题[归纳].pdf
Interior gateway protocols such as Intermediate System-to-Intermediate System (IS-IS) are used in conjunction with the... Mastering IS-IS, regardless of its simplicity, has been a daunting task for many.
可参考链接:is-a和has-a的区别 1、has a 关系 has a :一个类中使用了另外一种自定义的类型 类型: 系统类型 str、 int、 float、 list 、dict 、 tuple、 set 自定义类型 算是自定义的类,都可以将其当成一...
After this string has been received the AT Command processor is ready to accept AT commands. If the Applications core was rebooted or restarted for any reason that wasn’t a normal power-on sequence, ...
This Cortex-A Series Programmer’s Guide is protected by copyright and the practice or implementation of the information herein may be protected by one or more patents or pending applications. No part...
UML类图的标记语言我都忘了我记了多少遍,忘了...is-a和has-a is-a 可以分为继承和实现,依据:是否有实体函数实现来继承,如果虚函数,则为实现 has-a:包括四种关联关系的,组合,聚合,关联和依赖,依据关系强弱排名
As architects and engineers have ... Since security is easier to enforce with visibility and consistency across systems, the hybrid model poses a challenge since consistency is not always achievable
hprof-conv.exe The connection to adb is down, and a severe error has occured
Unit 8 基础要点归纳及...8. My ______ (third) brother is a doctor. 本单元的知识点主要包括序数词的规则和用法,以及月份单词的记忆。学生需要掌握序数词的构成方法和使用场景,并牢记十二个月份单词的英语表达。
1. **Has-a(包含关系)与Is-a(继承关系)** - **Has-a**:表示一个对象包含另一个对象的实例,例如,一个`Car`类可能包含一个`Engine`实例变量,即`Car` has-a `Engine`。这种关系可以通过实例变量来实现,不一定...
Invalid property 'error_view' of bean class [com.demo.controller.action.AuthorAction]: Bean property 'error_view' is not writable or has an invalid setter method. Does the parameter type of the ...
IPython is a powerful interactive shell that features easy editing and recording of a work session, and supports visualizations and parallel computing. The Software Carpentry Course teaches basic ...
Ipopt (Interior Point OPTimizer, pronounced eye-pea-Opt) is a software package for large-scale nonlinear optimization. Ipopt is written in C++ and is released as open source code under the Eclipse...
applied work, Arthur Getis has been a major contributing figure in this development. In this volume, we take both a retrospective and a prospective view of the field. We use the occasion of the ...
This is believed to be a bug in the Windows clipboard and a work around hasn't been found yet. * Asynchronous targets appears to be broken in the current release. * When TDropFileTarget....
A revision that really is-the WISC-R T E S T R E V I E W A REVISION THAT REALLY IS-THE WISC-11 ALAN KRICHEV ?‘he Lakehead Hoard of Erheatiim ’I’hwder Hay, Oirtario Author : David Wechsler...
This book has a completely updated content with expanded coverage of the topics of utmost importance to networking professionals and students, including P2P, wireless, network security, and network ...