Code Style and Conventions

Why: Understand the coding style and conventions used in the codebase to ensure consistency, readability, and maintainability.

Value Objects

The codebase uses Value Objects to represent domain concepts.

  • Example:
public class CustomerId : ValueObject
          {
              public override Validation Validate() => Value > 0 ? Validation.Ok : Validation.Invalid("Customer IDs cannot be zero or negative.");
          }
          
  • Usage:
    • Use Value Objects to represent domain concepts instead of primitives.
    • The ValueObject class provides a base implementation for creating Value Objects.

Validation

Value Objects are validated to ensure that they meet the requirements of the domain.

  • Example:
public override Validation Validate() => Value > 0 ? Validation.Ok : Validation.Invalid("Customer IDs cannot be zero or negative.");
          
  • Usage:
    • Validation is performed in the Validate() method of the Value Object.
    • The Validation class provides a way to represent the result of validation.

Immutability

Value Objects are immutable, meaning that their values cannot be changed after they are created.

  • Example:
var customerId = CustomerId.From(42);
          
  • Usage:
    • Use the From() method to create new instances of Value Objects.

Benefits

  • Improved Code Readability: Value Objects make it easier to understand the code and the domain concepts it represents.
  • Enforced Validation: Value Objects ensure that domain objects are valid.
  • Immutability: Value Objects are immutable, which makes them easier to reason about and prevents unexpected changes.

Source:


          ## Top-Level Directory Explanations
          
          <a class='local-link directory-link' data-ref="samples/" href="#samples/">samples/</a> - This directory contains example projects demonstrating the usage of StringlyTyped library.
          
          <a class='local-link directory-link' data-ref="src/" href="#src/">src/</a> - This directory contains the source code of the StringlyTyped library.
          
          <a class='local-link directory-link' data-ref="tests/" href="#tests/">tests/</a> - This directory contains unit tests for the StringlyTyped library. It includes benchmark tests and small tests.