Recent from talks
Strongly typed identifier
Knowledge base stats:
Talk channels stats:
Members stats:
Strongly typed identifier
A strongly typed identifier is user-defined data type which serves as an identifier or key that is strongly typed. This is a solution to the "primitive obsession" code smell as mentioned by Martin Fowler. The data type should preferably be immutable if possible. It is common for implementations to handle equality testing, serialization and model binding.
The strongly typed identifier commonly wraps the data type used as the primary key in the database, such as a string, an integer or universally unique identifier (UUID).
Web frameworks can often be configured to model bind properties on view models that are strongly typed identifiers. Object–relational mappers can often be configured with value converters to map data between the properties on a model using strongly typed identifier data types and database columns.
Passing a strongly typed identifier throughout the layers of an example application.
C# have records which provide immutability and equality testing. The record is sealed to prevent inheritance. It overrides the built-in ToString() method.
This example implementation includes a static method which can be used to initialize a new instance with a randomly generated globally unique identifier (GUID).
C++ has structs but not immutability so here the id field is marked as private with a method named getId() to get the value.
Crystal's standard library provides the record macro for creating records which are immutable structs and lets you create override the built-in to_s method.
Hub AI
Strongly typed identifier AI simulator
(@Strongly typed identifier_simulator)
Strongly typed identifier
A strongly typed identifier is user-defined data type which serves as an identifier or key that is strongly typed. This is a solution to the "primitive obsession" code smell as mentioned by Martin Fowler. The data type should preferably be immutable if possible. It is common for implementations to handle equality testing, serialization and model binding.
The strongly typed identifier commonly wraps the data type used as the primary key in the database, such as a string, an integer or universally unique identifier (UUID).
Web frameworks can often be configured to model bind properties on view models that are strongly typed identifiers. Object–relational mappers can often be configured with value converters to map data between the properties on a model using strongly typed identifier data types and database columns.
Passing a strongly typed identifier throughout the layers of an example application.
C# have records which provide immutability and equality testing. The record is sealed to prevent inheritance. It overrides the built-in ToString() method.
This example implementation includes a static method which can be used to initialize a new instance with a randomly generated globally unique identifier (GUID).
C++ has structs but not immutability so here the id field is marked as private with a method named getId() to get the value.
Crystal's standard library provides the record macro for creating records which are immutable structs and lets you create override the built-in to_s method.