Vyčlení spoločné chovanie do objektu, ktorý ho vykoná pre viac tried.
class Movable { position() { throw new Error('abstraktná metóda'); } setPosition(x, y) { throw new Error('abstraktná metóda'); }} class Circle extends Movable { position() { return this.center; } setPosition(x, y) { this.center = { x, y }; }} class Rectangle extends Movable { position() { return this.topLeft; } setPosition(x, y) { this.topLeft = { x, y }; }} // The servant. Moving is neither in the circle nor in the rectangle — it is here.class Mover { move(shape, dx, dy) { const p = shape.position(); shape.setPosition(p.x + dx, p.y + dy); }} const mover = new Mover();mover.move(circle, 10, 0);mover.move(rectangle, 10, 0);