{
  "id": "enwiki-001243542283",
  "slug": "servant-design-pattern",
  "title": "Servant (design pattern)",
  "qid": "",
  "lead": "In software engineering, the servant pattern defines an object used to offer some functionality to a group of classes without defining that functionality in each of them. A Servant is a class whose instance (or even just class) provides methods that take care of a desired service, while objects for which (or with whom) the servant does something, are taken as parameters.",
  "body": "In software engineering, the servant pattern defines an object used to offer some functionality to a group of classes without defining that functionality in each of them. A Servant is a class whose instance (or even just class) provides methods that take care of a desired service, while objects for which (or with whom) the servant does something, are taken as parameters. == Example== This simple Java example shows the situation described above. This example is only illustrative and will not offer any actual drawing of geometric objects, nor specification of what they look like. // Servant class, offering its functionality to classes implementing // Movable Interface public class MoveServant { // Method, which will move Movable implementing class to position where public void moveTo(Movable serviced, Position where) { // Do some other stuff to ensure it moves smoothly and nicely, this is // the place to offer the functionality serviced.setPosition(where); } // Method, which will move Movable implementing class by dx and dy public void moveBy(Movable serviced, int dx, int dy) { // this is the place to offer the functionality dx += serviced.getPosition().xPosition; dy += serviced.getPosition().yPosition; serviced.setPosition(new Position(dx, dy)); } } // Interface specifying what serviced classes needs to implement, to be // serviced by servant. public interface Movable { public void setPosition(Position p); public Position getPosition(); } // One of geometric classes public class Triangle implements Movable { // Position of the geometric object on some canvas private Position p; // Method, which sets position of geometric object public void setPosition(Position p) { this.p = p; } // Method, which returns position of geometric object public Position getPosition() { return this.p; } } // One of geometric classes public class Ellipse implements Movable { // Position of the geometric object on some canvas private Position p; // Method, which sets position of geometric object public void setPosition(Position p) { this.p = p; } // Method, which returns position of geometric object public Position getPosition() { return this.p; } } // One of geometric classes public class Rectangle implements Movable { // Position of the geometric object on some canvas private Position p; // Method, which sets position of geometric object public void setPosition(Position p) { this.p = p; } // Method, which returns position of geometric object public Position getPosition() { return this.p; } } // Just a very simple container class for position. public class Position { public int xPosition; public int yPosition; public Position(int dx, int dy) { xPosition = dx; yPosition = dy; } } ==References==",
  "categories": [
    "23000992",
    "24043274",
    "26157654",
    "27695885"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1243542283",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1725232546.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001243542283",
    "type": "webpage",
    "title": "Servant (design pattern)",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/servant-design-pattern",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          15
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          15
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001243542283",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1243542283",
    "note": "Immutable snapshot enwiki-001243542283"
  }
}