Eviscerated Object

An object which has been eviscerated, so that only its guts remain; the original object itself is gone.

For example:

 class Point
 {
 private double x ;
 private double y ;
 // methods and stuff
 }

Is eviscerated to:

 double x ;
 doubly y ;

Evisceration can be used as a time or space optimisation; it saves the time and space overhead of an object. This is useful if your language or runtime doesn't do InlineObjects?; most JVMs don't.

EvisceratedObjects are useful as variables and as parameters. The annoying thing about EvisceratedObjects is that you can't return them from methods in most languages, as you can usually only return one thing.

EvisceratedObjects can be hidden inside collections, behind an OO interface; this is known as a CrossSection.

For example:

 class PointArray
 {
 private double[] xs ;
 private double[] ys ;
 // constructor etc
 public Point get( int i )
 {
 return new Point( xs[i], ys[i] ) ;
 }
 public void set( int i, Point p )
 {
 xs[i] = p.x() ;
 ys[i] = p.y() ;
 }
 }

A subtle advantage of EvisceratedObjects is that you can use them without ever having a real object. This might be useful if the real object is for some reason much more expensive than the sum of its parts, or requires some magic other than its parts to create.

For example, say you want to traverse a tree-structured XML document. In particular, you want to apply some operation to each element. If you wanted to pass an Element object to the operation, you would probably have to build Element objects which knew about their child elements, which in turn knew about their children, etc, so you would have to render the entire document as a tree before you could start. If you instead pass an eviscerated Element (just its name, attributes and perhaps any text content), you avoid this, and so are able to traverse the document without loading the entire thing at once.


See also BoxingConversions, TypeErasure


RefactorMe


EditText of this page (last edited September 3, 2007) or FindPage with title or text search