The decorator pattern is one that favours composition over inheritance [another OOP paradigm that is useful to learn about]
The main benefit of the decorator pattern - over subclassing is to allow more mix & match options. If you have, for instance, 10 different behaviours that a window can have, then this means - with subclassing - you need to create every different combination, which will also inevitably include a lot of code reuse.
However, what happens when you decide to add in a new behaviour?
With the decorator, you just add a new class which describes this behaviour, and that's it - the pattern allows you to effectively drop this in without any modification to the rest of the code.
With sub-classing, you've got a nightmare on your hands.
One question you asked was "how does subclassing change the parent class?" It's not that it changes the parent class; when it says an instance, it means any object you've 'instantiated' [if you're using Java or C#, for instance, by using the new
command]. What it's referring to is, when you add these changes to a class, you've got no choice for that change to be there, even if you don't actually need it.
Alternatively, you can put all his functionality into a single class with it turned on/off via flags... but this ends up with a single class that becomes larger and larger as your project grows.
It's not unusual to start your project this way, and refactor into a decorator pattern once you hit an effective critical mass.
An interesting point that should be made: you can add the same functionality multiple times; so you could, for instance, have a window with double, triple or whatever amount or borders as you require.
The major point of the pattern is to enable run-time changes: you may not know how you want the window to look until the program is running, and this allows you to easily modify it. Granted, this can be done via the subclassing, but not as nicely.
And finally, it allows for functionality to be added to classes that you may not be able to edit - for example in sealed/final classes, or ones provided from other APIs
In a clean design object in a given tree should be used with an uniform interface. Your doubts reflects a design smell.
The goal of having object trees in scenes is to be able to apply geometric transformations to a group of objects. So if you have objects that can't move, they don't belong to the tree. It does not make sense.
Here is a possible solution. You can have a render class which can have background objects, and the root of the movable objects. All the movable objects can move. A transformation applied to an object is propagated to its children.
To render the scene, you have to render both the unmovable background objects, and the actual scene by calling a render function on the root.
Best Answer
The relationship being described in composite design patterns isn't a subclass relationship, it's a collection relationship. In other words, it's about treating a tuna the same as a school of tuna. That way for operations like translating, rotating, scaling, drawing, etc. the caller doesn't need to care if it is acting on one object or an entire collection.