Delegation is a design pattern where an object delegates responsibility for certain tasks to another object. Instead of doing the work itself, the delegating object asks another object (delegate) to perform the work.
“Has-A” relationship: The delegating object “has a” reference to the delegating object and uses it to delegate responsibilities.
Use Case: Useful when you want to separate concerns and avoid making a class too complex.
Steps
Create a class that performs the main task (Delegate).
Create a class that delegates tasks to the delegate class.
The delegator calls methods on the delegate class to perform specific tasks.