Search code examples
actionscript-3functiongetclone

To clone or not to clone


I wrote a Scale9Bitmap class in AS3 and it requires the dev to set the BitmapData and a Rectangle for the scale9Grid. I'm wondered what is customary for the public get functions of both. Do I return a clone of each to make it free of hanging references, but not as memory-friendly? or do I leave that up to the dev and return the original instances?


Solution

  • Leave it up to the developer. The developer is able to clone it if required. However this is very error prone. Usually you would shoot for immutable state and return a clone. But this is a bad idea with AS3 as you have already mentioned.