toString() advice

Hej all !

It’s not really related with Haxe, but I wanted to ask the haxe community for advice.
I often use implicit toString() function especially with DB class objects (with SPOD for example) but I realized that sometime I need to have the class name and the ID (+ others fields depending on the class), sometimes only the ID (+ others fields depending on the class) and sometimes just the fields depending on the class.

For example with an Address class I sometimes need to have :

  • Address#154 : 13 street, Paris France (for debug for example)
  • #154 : 13 street, Paris, France (for a drop down for example that lists many adresses so I have to distinguish the same adresses but stored in different IDs…)
  • 13 street, Paris, France (for a simple display of the address)

I certainly overthink here, there is many ways to do that but I want to ask you maybe someone has an interesting approach for this ?

Thanks for reading,

1 Like