mardi 14 septembre 2021

Creating a singleton for each instance of a class

I have a python class, let's call it C. it takes a string in it's constructor. how could i make sure (design-wise) that

x = C('a')
y = C('b')
z = C('a')

this configuration leads to x and y pointing to different places, and x and z pointing to the same place? meaning

x is y == False
x is z == True

Aucun commentaire:

Enregistrer un commentaire