dimanche 17 février 2019

What is the design pattern called where multiple objects reference a central data object?

I have a multitude of objects that all reference data from a single object, and I'm not really sure how to name things internally.

When my game starts, I load a bunch of data related to weapons from a JSON file into a central database with information like name, description, damage, etc. Whenever I create a physical copy of that weapon in the game world, I create an object that references that original data with its own data (like position, owner, etc.). That way if I have 50 iron axes laying about the game world, their data is pretty light on the save file and any balance changes will be reflected in all items as well.

The code looks like this basically:

class ItemRecord
{
    public string Name { get; }
    public string Description { get; }

    // etc
}

class Item
{
    private ItemRecord itemRecord;

    public string Name { get { return itemRecord.Name; } }
    public string Description { get { return itemRecord.Description; } }

    Item(ItemRecord itemRecord) { this.itemRecord = itemRecord; }

    // etc        
}

I don't really like the name "ItemRecord" though, as it doesn't really convey much of anything, and I'm sure this has a design pattern name that I could use instead.

Any tips on where I could read more about this pattern?

Thanks.

Aucun commentaire:

Enregistrer un commentaire