In short, the Decorator is a pattern that permits the addition of new functionalities to an existing object without altering it. And this is made possible by creating a decorator class that wraps the original class. And with this mechanism, we easily attach but also detach new behaviors to an object.
Let's review the following diagram to visualize the Decorator's structure before diving deeply into the subject matter:
The IWeapon interface establishes an implementation contract that will maintain a consistent method signature between the decorated object and its decorators. WeaponDecorator wraps the target object, and the concrete decorator classes (WithGrip and WithStabilizer) decorate it by enhancing or overriding its behaviors.
The method signatures and the overall structure of the decorated object are not modified during the process, just its behaviors or property...