User:Marcelofinki/Transmogrifier (Computer Science)
Appearance
Transmogrifier (Computer Science)
[edit](sometimes referred to as Demeter Transmogrifiers)
A Demeter Transmogrifier is a small “wrapper” method used to propagate a method/property implemented in an another subsidiary object.
Sample
[edit]Imagine three objects: Driver, Car, Engine.
Object Driver
depends on object Car
.
Object Car
depends on object Engine
.
Object Engine
has a method Start
.
Driver{
Car myNewCar = new Car() ;
myNewCar.Start() ;
}
Car{
Engine myEngine = new Engine() ;
public Start(){
myEngine.Start() ;
}
}
Engine{
public Start(){
// ... some statements ...
mySparkPlug.Spark() ;
// ... some statements ...
}
}
In the above example, car.start() is a transmogrifier of engine.start().
Advantage:
Driver
does not need to "know" aboutEngine
.- The driver just uses the
Start
method offered by theCar
object. A change on the Engine.Start() method will affect the Car object but not the Driver object, since the driver did not use themyNewCar.myEngine.Start()
method.
Disadvantage:
- The programmer must code the car.start() method.