Hello list,

Lets say I have a class with a public getter to a private var which holds an Array.
Some other class can do this then:

var tArr:Array = class.myArray;

I can then do this:
tArr.push(int) and the content of the array has changed without the class knowing. This is in most cases I use it ok, but now I am wondering how to deal with it when I really want to create a read only array.

I am aware that I can copy it, but then this can be very expensive when it is requested a lot of times and it is a relative big array.

So i was thinking the following.

class A{
private var pArray:Array = [1,2,3]

public function get list():listArray{
        return new listArray(pArray);
}

}

class listArray{

private var pList:Array
public function listArray(tArr:Array):void{
        pList = listArray
}

override function push():void{
        throw new IllegalOperationError()
}

}

I would have to override all the public methods of Array which can be a pain.

My question is.
How would I prevent users from doing this:
listArray[n] = 'whatever'


Much appreciated

Jiri
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to