我想了解uml合成到代码的转换。 我有三个代码狗有内存的例子的问题。这三个例子可以被认为是一个组成(uml含义的组成)?试图将uml合成转换成代码[uml]
实施例1
class Memory {
// CODE
}
class Dog {
private Memory variable;
Dog(Memory variable) {
this.variable = variable;
}
}
class Factory {
Dog createDog() {
Memory memory = new Memory() // memory contains reference to object Memory only moment and after create dog don't use it
return new Dog(memory);
}
}
实施例2
class Memory {
// CODE
}
class Dog {
private Memory variable;
Dog(Memory variable) {
this.variable = variable;
}
}
class Factory {
Dog createDog() {
return new Dog(new Memory());
}
}
实施例3
class Memory {
// CODE
}
class MemoryFactory {
Memory createMemory() {
return new Memory();
}
}
class Dog {
private Memory variable;
Dog(MemoryFactory memoryFactory) {
this.variable = memoryFactory.createMemory();
}
}
class Factory {
Dog createDog() {
MemoryFactory factory = new MemoryFactory()
return new Dog(factory);
}
}
有点不同的示例:
class Memory {
// CODE
}
class Dog {
private Memory variable;
Dog() {
this.variable = new Memory();
Other other = new Other();
other.method(variable);
}
}
class Other {
void method(Memory memory) {
// code which don't save reference to memory
}
}
这是进一步组合物?
除了您还有一个关联之外,您的最后一个示例基本上没有区别。请先尝试理解答案。 –