I'm using ActionScript3 to develop a Data Access Layer for an application another developer is working on in my team. One of the objects, lets call it User
is expensive to construct. Each user has a unique ID number so I can tell if they've been created before or not, and all User
objects are stored in an array somewhere else.
I want to be able to restrict it so that there can be only once instance of a User
per ID. I.E. each user has to be unique, and requests for an already constructed User
should receive the pre-constructed User
.
If I was using a sane, well-designed language I would simple make it a private constructor and force all requests for the object to go through a function that cached things. But flash doesn't allow private constructors (only public and internal, neither of which will work). How can I achieve this?