There are two types of delegation:

Explicitly. Can be implemented in any object-oriented language.

Implicitly. Requires language support for this feature.

Explicitly Delegation

As I have already said, it can be implemented in any OOP language. Let’s look at the example:

This example was written in Java. As you have probably noticed, we don’t use any language features to implement Delegation pattern. Keep in mind that you can use any implementation of type A:

Of course, you can also use interfaces:

This has been mentioned previously: delegation pattern builds mutable relationship between classes, that’s why it’s a really flexible and powerful mechanism. As indicated in previous examples, Explicitly Delegation requires a lot of efforts to write methods that contain forwarding calls to delegate instance.

That’s why many languages support this feature out of the box.

Implicitly Delegation

Language-level feature that allows an object designate another one as its “parent” is called Implicitly Delegation. It, in particular, is divided into unanticipated delegation and anticipated delegation. Case, when delegation structure can be changed dynamically, is called unanticipated, whereas the second type refers to the fact that object can’t change parent during their life-cycle.