少なくとも3つのデザインパターンを使用するプロジェクトを行う必要があります。私は最初にデコレータパターンでビルダーパターンを使用しようとしましたが、私の教師は両方のパターンを複合パターンで接続する必要があると私に教えてくれました。私はumlの構造を想像しようとしましたが、それは私にとっては難しすぎます。誰も私を助けることができますか?それらを接続する方法?デザインパターン:Builder + Decorator + Composite
0
A
答えて
1
gofは言う:
デコレータは一成分と縮重合成と見なすことができます。しかし、デコレータは、オブジェクトの集約を目的としたものではありません。
と:
Aコンポジット(163)は、ビルダーは、しばしば構築するものです。
ここではデコレータとのコンポジットです。ビルダーを追加しようとします。
package p;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class So44300051 {
static abstract class Component {
Component(String name) {
this.name=name;
}
abstract boolean add(Component component);
abstract boolean remove(Component component);
abstract List<Component> children();
void visit() {
System.out.println(this);
if(this instanceof Decorator1)
((Decorator1)this).additionalBehaviour1();
for(Component child:children())
child.visit();
}
final String name;
}
static class Composite extends Component {
Composite(String name) {
super(name);
}
@Override boolean add(Component component) {
return children.add(component);
}
@Override boolean remove(Component component) {
return children.remove(component);
}
@Override List<Component> children() {
return Collections.unmodifiableList(children);
}
@Override public String toString() {
return "Composite [name="+name+"]";
}
final List<Component> children=new ArrayList<>();
}
static class Leaf extends Component {
Leaf(String name) {
super(name);
}
@Override boolean add(Component component) {
return false;
}
@Override boolean remove(Component component) {
return false;
}
@Override List<Component> children() {
return Collections.emptyList();
}
@Override public String toString() {
return "Leaf [name="+name+"]";
}
}
static abstract class Decorator extends Component {
Decorator(Component component) {
super(component.name);
this.component=component;
}
@Override boolean add(Component component) {
return this.component.add(component);
}
@Override boolean remove(Component component) {
return this.component.remove(component);
}
@Override List<Component> children() {
return this.component.children();
}
@Override public String toString() {
return getClass().getSimpleName()+" "+component;
}
final Component component;
}
static class Decorator1 extends Decorator {
Decorator1(Component component) {
super(component);
}
void additionalBehaviour1() {
System.out.println("additional behaviour 1.");
}
}
public static void main(String[] args) {
Component root=new Composite("root");
root.add(new Leaf("leaf 1"));
root.add(new Decorator1(new Leaf("leaf2")));
root.visit();
}
}
0
Design Pattern Combination Image
レッツは、我々は多くのプロパティ(コンポーネント)今、このコンポーネントは、他の成分を含有することができますがあり複雑なオブジェクトを持っていると言います。したがって、Builderパターンを使用してこのComplexオブジェクトを作成すると、結果のオブジェクトはコンポジットになります そして、このコンポーネントは、デコレータデザインパターンを使用して追加の責任を適用することによってさらに変更できます。
コマンドとコマンド コンポーネントのグループ - コマンドは、コンポーネントを拡張 - 今すぐこのコンポーネントは以下のように渡される複数のパラメータを持つことができ、コマンド--sayエコーのリストが含まれているエコー、
をエコーします - バットコマンドエコー GroupOfCommandは、コンポーネントを拡張言います(); setArgument( "hello")。setArgument( "world")。build();ComponentBuilder()。setCommand( "echo")。
デコレータので Component.execute()メソッドは、デコレータ の一部であるWrapWithBrackerDecorator方法は
public String execute(){
return "(" +component.execute() +")";
}
ようになり実行するコンポーネントを拡張し、コンポーネント を含有します
関連する問題
- 1. sql builderのデザインパターン
- 2. Builderデザインパターンを使用したAutomapper
- 3. ビルダー対Decoratorパターン
- 4. サブクラス化と必須パラメータを含むBuilderデザインパターン?
- 5. @Transient vs decorator
- 6. Python Decoratorのバリデーション
- 7. Zend Form captcha Decorator
- 8. Japura Swing - Decorator
- 9. Django Compositeユーザ名
- 10. Object.Assign on Composite Object
- 11. ラジオボタン付きZend Decorator?
- 12. Composite Datawindowオブジェクトにアクセスする
- 13. Compositeパターンの再利用
- 14. 設定可能なソフトウェアのBuilderとDecoratorパターンを設定するにはどうすればよいですか?
- 15. 複合デザインパターン
- 16. オブジェクト指向分析とデザイン、デザインパターン
- 17. Eclipse Decoratorのイメージの使用方法
- 18. プロパティ値のWPF Decorator子ベースの変更
- 19. Redis get decoratorを設定します
- 20. @connect decoratorをredux-sagaで使うには?
- 21. Python Decorator 3.0とデコレータへの引数
- 22. Aurelia Dependency Injection Decoratorが動作しない
- 23. Decoratorパターンチェーンメソッドはどのように呼び出されますか?
- 24. Cassandra Compositeのキーを理解する
- 25. Gradle Composite異なるプロジェクトタイプ(ant、maven)でビルド
- 26. SSISデザインパターン
- 27. Async.jsデザインパターン
- 28. JavaScriptデザインパターン
- 29. デザインパターンは、
- 30. DAOデザインパターン