Here's the situation.
The Items abstract class with a boolean flag
:
public abstract Items {
public boolean flag;
public abstract void display();
}
A concrete implementation:
public ConcreteItem extends Items {
@Override
public void display() {
// do things...
}
}
The decorator:
public class ItemDecorator implements Items {
public Items item;
public ItemDecorator(Items item){
this.item = item;
}
@Override
public void display() {
this.item.display();
}
}
and the concrete decorator:
public class ConcreteDecorator extends ItemDecorator {
public ConcreteDecorator(Items item) {
super(item);
}
@Override
public void display() {
super.display();
System.out.print("Adding decorators to Item...");
}
}
So when I create an Items
object decorated by a ConcreteDecorator
, how could I to change the variable flag
in ConcreteDecorator
in run-time?
Aucun commentaire:
Enregistrer un commentaire