In this example, we demonstrate how to exercise fine-grained control over what methods we consume from a role. We have a Restartable role which provides an is_paused attribute, and two methods, stop and start.

Then we have two more roles which implement the same interface, each putting their own spin on the stop and start methods.

In the Restartable::ButUnreliable role, we want to provide a new implementation of stop and start, but still have access to the original implementation. To do this, we alias the methods from Restartable to private methods, and provide wrappers around the originals (1).

Note that aliasing simply adds a name, so we also need to exclude the methods with their original names.

Exclusion and renaming are a power tool that can be handy, especially when building roles out of other roles. In this example, all of our roles implement the Restartable role. Each role provides same API, but each has a different implementation under the hood.

You can also use the method aliasing and excluding features when composing a role into a class.