英文:
<<use>> or <<create>> relationship in program code
问题
我不清楚在程序代码中 <
谢谢
英文:
I can't figure out what a <<use>> or <<create>> relationship looks like in program code? Can someone give me an example?
Thanks
答案1
得分: 1
The «Create»
依赖表示一个类的对象创建另一个类的实例。一个典型的例子是工厂模式。维基百科文章展示了带有创建依赖的 UML 类图以及示例代码。
The «use»
依赖表示一个类的对象使用另一个类的实例,因此需要了解另一个类。这其他 SO 回答解释了所有细节。一个典型的例子是某些操作(方法)具有另一个类类型的参数:
class B { ... }
class A {
public doSomething(B b) { ... }
}
英文:
The «Create»
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 «use»
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) { ... }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论