<> 或 <> 在程序代码中的关系

huangapple go评论47阅读模式
英文:

<<use>> or <<create>> relationship in program code

问题

我不清楚在程序代码中 <> 或 <> 关系是什么样子的?有人可以给我一个例子吗?

谢谢

英文:

I can't figure out what a <&lt;use>> or <&lt;create>> relationship looks like in program code? Can someone give me an example?

Thanks

答案1

得分: 1

The &#171;Create&#187; 依赖表示一个类的对象创建另一个类的实例。一个典型的例子是工厂模式。维基百科文章展示了带有创建依赖的 UML 类图以及示例代码。

The &#171;use&#187; 依赖表示一个类的对象使用另一个类的实例,因此需要了解另一个类。这其他 SO 回答解释了所有细节。一个典型的例子是某些操作(方法)具有另一个类类型的参数:

 class B { ... }
 class A {
   public doSomething(B b) { ... }
 }

<<use>> 或 <<create>> 在程序代码中的关系

英文:

The &#171;Create&#187; dependency says that an object of one class creates instances of another one. A typical example is the factory pattern. The wikipedia article shows both the UML class diagram with create dependency and an example code.

The &#171;use&#187; dependency tells that objects of one class uses instances of another class and therefore need to know about that other class. This other SO answer explains all the details. A typical example is when that some operations (methods) have parameters of the type of the other class:

 class B { ... }
 class A {
   public doSomething(B b) { ... }
 }

<<use>> 或 <<create>> 在程序代码中的关系

huangapple
  • 本文由 发表于 2023年2月19日 20:28:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75500145.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定