## Exercise 08

Moderatoren: pmueller, SE - Design and Construction

Ben Kohr
Windoof-User
Beiträge: 34
Registriert: 14. Apr 2015 17:41

### Exercise 08

Regarding exercise 08, I have some questions:

1. Task 1, Task 2: Should we annotate each single method with @Operation in the code that appears in Composite, Leaf or Component and that is declared by Component? This is my current understanding of the @Operation annotation. The same question arises for the Decorator pattern.

2. Task 1: Is it okay if there is a class between a Composite and the Component in the type hierarchy? Should we in this case not label the in-between class (my current approach).

4. Task 2: Should we use further annotations than those that are imported for the second task? I suppose yes, just wanted to make sure.

5. Task 2: Should we search for a Composite-Pattern-Client in task 2, as the code is only a library and not used from the outside?

6. Task 2: How should we implement the methods weight and label for a SubGraph? Or does it not matter for the upload?

Best,
Ben

AizazZaidee
BASIC-Programmierer
Beiträge: 106
Registriert: 20. Apr 2016 22:49

### Re: Exercise 08

I was also thinking about Enum but then I think they should be because whole Strategy can be implemented as one single Enum, for example:

Code: Alles auswählen

//Implementation + Interface
public enum Strategy {

STRATEGY_A {
@Override
void execute() {
System.out.print("Executing strategy A");
}
},

STRATEGY_B {
@Override
void execute() {
System.out.print("Executing strategy B");
}
};

abstract void execute();
}

//Usage

public static void main(String[] args) {
UseStrategy useStrategy = new UseStrategy();
useStrategy.perform(Strategy.STRATEGY_A);
useStrategy.perform(Strategy.STRATEGY_B);
}

private void perform(Strategy strategy) {
strategy.execute();
}
I guess the one you talking about is default Context.

pmueller
Moderator
Beiträge: 87
Registriert: 25. Jan 2018 11:14

### Re: Exercise 08

Hi,
Ben Kohr hat geschrieben:
1. Jul 2018 12:16
1. Task 1, Task 2: Should we annotate each single method with @Operation in the code that appears in Composite, Leaf or Component and that is declared by Component? This is my current understanding of the @Operation annotation. The same question arises for the Decorator pattern.
Yes.
Ben Kohr hat geschrieben:
1. Jul 2018 12:16
2. Task 1: Is it okay if there is a class between a Composite and the Component in the type hierarchy? Should we in this case not label the in-between class (my current approach).
If this in-between does not really take part in the given pattern, it might not be necessary to annotate it (or just with the annotations of a different pattern).
Ben Kohr hat geschrieben:
1. Jul 2018 12:16
Why not?
Ben Kohr hat geschrieben:
1. Jul 2018 12:16
4. Task 2: Should we use further annotations than those that are imported for the second task? I suppose yes, just wanted to make sure.
Yes. These imports are just included because of the name clash.
Ben Kohr hat geschrieben:
1. Jul 2018 12:16
5. Task 2: Should we search for a Composite-Pattern-Client in task 2, as the code is only a library and not used from the outside?
If there is no client you cannot annotate it.
Ben Kohr hat geschrieben:
1. Jul 2018 12:16
6. Task 2: How should we implement the methods weight and label for a SubGraph? Or does it not matter for the upload?
Subgraph should have its own label defaulting to an empty String, and the weight should be the total weight of all contained elements.

Best,
Patrick

emod02
Neuling
Beiträge: 9
Registriert: 27. Apr 2018 19:35

### Re: Exercise 08

Hello,

Regarding task 2.3: we should implement the "getElementsSorted" method in the "SubGraph", right?

Greets

pmueller
Moderator
Beiträge: 87
Registriert: 25. Jan 2018 11:14

### Re: Exercise 08

emod02 hat geschrieben:
3. Jul 2018 15:38
Regarding task 2.3: we should implement the "getElementsSorted" method in the "SubGraph", right?
Yes