Strongly typed identifier

This is a solution to the "primitive obsession" code smell as mentioned by Martin Fowler.

[3] This example implementation includes a static method which can be used to initialize a new instance with a randomly generated globally unique identifier (GUID).

[6] Haskell can create user-defined custom data types using the newtype keyword.

This JavaScript example implementation provides the toJSON method used by the JSON.stringify()[9] function to serialize the class into a simple string instead of a composite data type.

[17] Furthermore, it implements the JsonSerializable interface which is used by the built-in json_encode function to serialize the class into a simple string instead of a composite data type.

[20] Python has data classes which provides equality testing and can be made immutable using the frozen parameter.

[22] This example implementation includes a static method which can be used to initialize a new instance with a randomly generated universally unique identifier (UUID).

This example implementation includes a static method which can be used to initialize a new instance with a randomly generated universally unique identifier (UUID).

[30] Zig have structs[31] with constants but by design does not have operator overloading[32] and method overriding.

A UML class diagram for a strongly typed identifier.
A UML class diagram for a strongly typed identifier.