java中 is a, is like,is kind of 分别代表什么意思?

Python017

java中 is a, is like,is kind of 分别代表什么意思?,第1张

1,is a 顾名思义是“...是一个...”的意思,体现在java里就是继承;

2,is like “...像...”在java里表示的是组合机制;

3,至于is kind of ,我好像没听过,应该和is a一个意思,都是指的继承

is-a 是继承关系。在继承关系中,一个子类继承于父类,其本身可以称之为父类。例如:狗继承于动物,可以说狗是一种动物。

has-a 是组成关系,在组成关系中,一个对象将一个或者多个其它对象作为自己的成员。

1. IS-A, HAS-A两种经典OO模式:

1.1 You can just use IS-A to figure out the relationship of Subclass and Superclass. If B is a A, that means class B extends class A. That's TRUE everywhere in the inheritance tree.

Example: Canine(犬科动物) is-A Animal, So Class Canine extends AnimalWolf is-A Canine, So class wolf extends CanineBut note you can't change their position, Animal is-A Canine never happen, so class animal never extends Canine.

1.2 HAS-A, we can remember a case: Bathroom HAS-A Tub, Tub NEVER HAS-A Bathroom, that means class Bathroom has a instance variable(field) of class tub.

as we can see:

public class Bathroom()

{ private Tub tub

Tub.flush()}

public class Tub()

{ public void flush()

{ //more flush code here. } }