package { // The actionscript_misc_Rectangle subclass implements Serializable directly public class actionscript_misc_Rectangle extends Shape implements Serializable { public var width:Number = 0; public var height:Number = 0; private var serializer:actionscript_misc_Serializer; public function actionscript_misc_Rectangle (fillColor:uint, lineColor:uint) { super(fillColor, lineColor) // Here is where the composition takes place serializer = new actionscript_misc_Serializer(); serializer.setRecordSeparator("|"); serializer.setSerializationVars(["height", "width", "fillColor", "lineColor"]); serializer.setSerializationObj(this); } public function setSize (w:Number, h:Number):void { width = w; height = h; } public function getArea ():Number { return width * height; } public function serialize ():String { // Here is where the actionscript_misc_Rectangle class forwards the serialize() // invocation to the Serializer instance stored in serializer return serializer.serialize(); } } }