Reputation: 227
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?
Upvotes: 0
Views: 392
Reputation: 387745
I would remove all logic, that actualizes the displayed state, from the setter and move it to some update
method and leave this just a reference to the object.
Forcing a clone with every get would be extremely unhandy, for example think of a simple size check or such..
Upvotes: 0
Reputation: 6715
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.
Upvotes: 1
Reputation: 15832
I'm not familiar with ActionScript but in other languages, I'd prefer to have the choice. So leave it to the dev.
Upvotes: 0