Generic Identity fields for basic server objects :)

Options
KEMBL
edited October 2011 in Photon Server
Hello, Boris, Tobias, and All!

:idea: Suggest to use generic Identity fields for basic server objects in next server releases.

Explain this idea on class Item.

In Item, one of the basic classes, was used Identity specification to have unique identification for their objects.

Unfortunately :( , this Id field have got string type which causes impact for equality operations and differ from usual SQL database id specification like int, or even bigint.

Yes, simple workaround #1: Make other Identity field for project needs, but this broke link to Item constructor (which used type string) and other classes which works with Item class already in core Photon logic.

Or, simple workaround #2: Make renew exists field

for example:
Was in Item:
public string Id { get; }

Will in MmoItem:
new public long Id { get; private set; } // private set for set in MmoItem constructor  

this not too difficult in realization, but in far project life we will need any time make every time brain cracks cast operations like:
int itemId = ((MmoItem)this.AttachedItem).IdInt;
in a case of #1

int itemId = ((MmoItem)this.AttachedItem).Id
in a case #2

which impacts to performance and have bad look syntax :shock:

What if you just give option to make basic classes through generic mechanism, like
public class MmoItem : Item<int>, IMmoItem

In a best case, this may be apply for other simple typed class fields like
public byte Type { get; }
and even other classes!

Or maybe this problem have any other approaches to resolve? :?:

Thx ahead!

Comments

  • Boris
    Options
    I actually tried different approaches to include generics, but it gets pretty ugly.

    Remember that Actor, InterestArea, ItemCache and all the messages being exchanged use Items...so they all would have to be generic as well: Actor<long> / Actor<Item<long>> and so on...

    It's much easier to use a string representation of your long id as ID.