ਡੈਕੋਰੇਟਰ ਪੈਟਰਨ ਆਬਜੈਕਟਸ ਨੂੰ ਲਪੇਟ ਕੇ ਵਿਵਹਾਰ ਜਾਂ ਜ਼ਿੰਮੇਵਾਰੀਆਂ ਨੂੰ ਗਤੀਸ਼ੀਲ ਰੂਪ ਵਿੱਚ ਜੋੜਦਾ ਹੈ — ਮੂਲ ਕਲਾਸ ਨੂੰ ਸੋਧੇ ਬਿਨਾ। ਇਹ ਕਾਰਜਸ਼ੀਲਤਾ ਨੂੰ ਵਧਾਉਣ ਲਈ ਸਬਕਲਾਸਿੰਗ ਦਾ ਇੱਕ ਲਚਕਦਾਰ ਵਿਕਲਪ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ, ਜਿਸ ਨਾਲ ਤੁਸੀਂ ਵਿਵਹਾਰਾਂ ਨੂੰ ਸੰਰਚਿਤ ਕਰ ਸਕਦੇ ਹੋ।
ਡੈਕੋਰੇਟਰ ਪੈਟਰਨ ਕੀ ਕਰਦਾ ਹੈ
DECORATOR → WRAP an object to add behavior, keeping the same interface:
→ the decorator wraps the original, adds its behavior, and delegates to the original
→ you can STACK decorators (wrap a wrapped object) → compose multiple behaviors
→ adds functionality WITHOUT modifying the original class or using subclassing
→ "wrap to extend" — flexible, composable behavior addition
