Skip to content

Add support for genericsΒ #18

@CodingSoot

Description

@CodingSoot

Background

When it comes to implementing generics, we should consider two main issues : param transformations and type constraints.

In general, a "param transformation" is a change in the type of a parameter. There are three kinds of param transformations :

  • Valid param transformations : Happens on the member parameters of an Entity, after the contentValidation step. Example : Age age becomes ValidAge age.
  • Non-null param transformations : Happens on a nullable member parameter of a ValueObject or Entity, when it's annotated with @NullFailure. Example : Age? age becomes Age age.
  • Null param transformations : Happens on a nullable member parameter (which should be an InvalidModddel) of a SimpleEntity, when it's annotated with @invalidParam, after the contentValidation step. Example : InvalidAge? age becomes Null age.

Additionally, we should keep in mind that :

  • Member parameters of entities must be modddels
  • For Iterable/Iterable2 entities, the member parameter must match the TypeTemplate

Solution

With all this in mind, let's see how we can implement generics :

  • βœ… For dependency parameters, there's no problem
  • βœ… For member parameters that don't have any param transformation, there's no problem. These would be :
    • The member parameters of ValueObjects that are not annotated with @NullFailure
    • The member parameters of Entities that are annotated with @validParam and aren't annotated with @NullFailure
  • πŸ”΄ For member parameters that have a valid param transformation : The type parameter must extend BaseModddel. However, there's no way to convert the type parameter to its valid version. We can either disable the valid param transformation for type parameters, or disallow type parameters in this case.
  • βœ… For member parameters that have a non-null param transformation : The type parameter must be non-nullable (ex : T extends Object), and the type of the member parameter must be nullable (T? param).
  • βœ… For member parameters that have a null param transformation : The type parameter must extend InvalidModddel, and there's no restriction on whether its nullable or not as long as the resulting type of the member parameter is nullable.

Another thing to consider is how these rules apply to the types of shared properties, knowing that a SharedProp has options to disable certain param transformations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions