Q:

Java: Decorator Pattern - reference to main abstract class

I have read this article about the decorator pattern and I have one question.
This class inhertis from the abstract class SandWichDecorator:
public class CheeseDecorator extends SandWichDecorator{
    Sandwich currentSandwich;

    public CheeseDecorator(Sandwich sw){
        currentSandwich = sw;
    }

    @Override
    public String getDescription(){
        return currentSandwich.getDescription() + ", Cheese";
    }
    @Override
    public BigDecimal price() {
        return currentSandwich.price().add(new BigDecimal("0.50"));
    }
}

Why is the reference to the abstract class Sandwich Sandwich currentSandwich; in the CheeseDecorator class?
Wouldn't it be easier to put it into the abstract class SandWichDecorator?
And every class extending SandWichDecorator would automatically have the reference.

A:

Yes, you are right. You can just have the current Sandwich in SandwichDecorator, like this: 
public abstract class SandwichDecorator implements Sandwitch {

    protected final Sandwitch current;

    public SandwichDecorator(Sandwitch current) {
        this.current = current;
    }

}

But, actually, you don't need even SandwichDecorator class. You can just have an interface Sandwich and implement it. It's not worth to have an abstract class just for holding the "decorated" reference:
interface Sandwich {
    String description();
    float price();
}

class BasicSandwich implements Sandwich {
    @Override
    public String description() {
        return "Sandwich";
    }    
    @Override
    public float price() {
        return 4f;
    }    
}

class CheeseSandwich implements Sandwich {   
    private final Sandwich origin;
    public CheeseSandwich(Sandwich origin) {
        this.origin = origin;
    }
    @Override
    public String description() {
        return origin.description() + " , Cheese";
    }    
    @Override
    public float price() {
        return origin.price() + 1f;
    }   
}

//More implementations of Sandwich

You can use it like this: 
Sandwich completeSandwich = new CheeseSandwich(new BasicSandwich());

Designing with interfaces is more flexible than with abstract classes. Every time you writes extends a little cat dies.

