samedi 27 décembre 2014

how can i improve a shallow copy of a singleton pattern?

I have a class whitch has a singleton implementation and a Clone() method for shallow copy never affecting initial singleton : class A Static Singleton A // ... Collection of data, array... () ... // private constructor of A() { if singleton == null initialize data () }



public function Get() as A
if Singleton == null)
{
singleton = new(A)
}

function Clone()
obj as A = new A()
A.Collections = copy of collection (*) // shallow copy : reference only of data array in List of Collection
return A


Remark :

I think that it is anti-pattern because singleton can be "clone"

Question : How can i benefit to the shallow copy with a good design pattern ?


Aucun commentaire:

Enregistrer un commentaire