“一个类实例化另一个”是什么?意思? [英] What does "a class instantiates another" mean?

查看:199
本文介绍了“一个类实例化另一个”是什么?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自GoF的设计模式:

From Design Pattern by GoF:


另一个有用的内容是哪个类实例化了
,其他实例
。我们使用虚线箭头来表示这一点,因为OMT不支持
。我们称此为创建
关系。箭头指向实例化的类。在
图B.lc中,CreationTool创建LineShape对象。

Another useful thing to show is which classes instantiate which others. We use a dashed arrowheaded line to indicate this, since OMT doesn't support it. We call this the "creates" relationship. The arrow points to the class that's instantiated. In Figure B.lc, CreationTool creates LineShape objects.

一个类实例化另一个在这里是什么意思?

What does "a class instantiates another" mean here?

谢谢。

推荐答案

表达它的另一种方式是一个类创建另一个实例。

Another way to phrase it would be "a class creates an instance of another", which makes it a little more obvious.

这只是意味着 Class A 在其中创建了 Class B 的实例(或 Class A 实例化 Class B )。

It just means that Class A creates an instance of Class B inside of it (or "Class A instantiates Class B").

例如,您可能有一个 Person 类,该类创建一个 Hand 类的实例,然后使用该类

For example, you might have a Person class, which creates an instance of a Hand class, which it then uses.

这篇关于“一个类实例化另一个”是什么?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆