dimanche 24 novembre 2019

Name of pattern where an object is stored by UUID

I am programming an application where I want to store Session information by a UUID. For this purpose, I wrote this code:

import uuid

class ObjectStore:
  def __init__(self):
    self.objects = {}

  def add(self, obj):
    uuid_value = uuid.uuid4() # UUID4 generates a random UUID
    self.objects[uuid_value] = obj
    return uuid_value

  def retrieve(self, uuid):
    return self.objects[uuid]

Is this structure a common pattern? If so, does it have a name?

Aucun commentaire:

Enregistrer un commentaire