Servant (design pattern)

For example: we have a few classes representing geometric objects (rectangle, ellipse, and triangle).

An interface is defined to ensure that serviced classes have methods that servant needs to provide desired behavior.

Thus the “moving” code appears in only one class which respects the “Separation of Concerns” rule.

There are two ways to implement this design pattern: This simple Java example shows the situation described above.

Eleventh Annual Conference on Innovation and Technology in Computer Science Education, University of Bologna.

Figure 1: User uses servant to achieve some functionality and passes the serviced objects as parameters.
Figure 2: User requests operations from serviced instances, which then asks servant to do it for them.