What does “a class instantiates another” mean?

2019-08-19 01:12发布

问题:

From Design Pattern by GoF:

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?

Thanks.

回答1:

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

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

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