Typely
GitHub
  • Overview
    • πŸ‘Welcome!
  • Validations
    • πŸ“Common
    • πŸ”’Number
    • βš–οΈComparable
    • ✏️String
  • Customize errors
    • 🌎Localization
    • πŸ”Sensitive data
  • General
    • 🧩Class VS Struct
    • πŸ–ΌοΈSupported frameworks
    • πŸš€Benchmarks
    • ⚠️Limitations
  • Design decisions
    • πŸ”„Conversions
    • ℹ️Use of interfaces
    • πŸ€Έβ€β™‚οΈUnderlying type comparison
    • πŸ’‚Validations
Powered by GitBook
On this page
Edit on GitHub
  1. Design decisions

Use of interfaces

PreviousConversionsNextUnderlying type comparison

Last updated 12 months ago

Why do generated types implements an interface?

  • First, because we can't use implicit conversion, we need to have some way to access the underlying value.

  • Second, to respect the open-close principle, we want developers to be able to add new functionality to their value object without having to modify the sources of the Typely generator.

  • Third, the use of interface reduces the redundancy such as for example converters. The same reason why Microsoft added the feature Generic Math with interfaces like INumber<T> over primitive types.

ℹ️
Preview Features in .NET 6 - Generic Math.NET Blog
Logo