umlの構成をコードに変換することを理解しようとしています。 Dogにメモリがあるコードの3つの例について質問があります。これら3つの例は、組成(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
}
}
これは、組成物は?
もう1つの関連性があることを除いて、最後の例との違いは基本的にありません。まず回答を理解してみてください。 –