Modddels
HomeGithubPub.dev
v0.2
v0.2
  • Motivation
  • Setup
  • Generalities
    • Modddels Overview
    • Validations & Validation steps
    • Structure of a Modddel
    • Member parameters & Dependency parameters
    • Usage
      • Data equality & toString
      • Pattern matching
      • Reading the fields
      • Reading the failures
      • CopyWith
  • ValueObjects
    • ValueObjects Overview
    • Creating a ValueObject
  • Entities
    • Entities Overview
    • ContentValidation & ContentFailure
    • ValidationSteps in Entities
    • SimpleEntity
      • Creating a SimpleEntity
      • Special Cases
    • IterableEntity & Iterable2Entity
      • IterableEntity / Iterable2Entity kinds
      • The Type Template
      • Creating an IterableEntity / Iterable2Entity
      • InvalidMembers Description
      • Special Cases
      • Creating your own IterableEntity / Iterable2Entity kind
  • Advanced Notions
    • The NullFailure Annotation
    • Using multiple parameters annotations
    • Class Hierarchy of ValueObjects
    • Class Hierarchy of Entities
    • Models that are always valid / invalid
  • Union of Modddels
    • Union of Modddels Overview
    • Basic Usage
    • Case-modddels pattern matching
    • Default Factory Constructor
    • Shared Properties
    • The Validate Methods
    • CopyWith
  • Unit-Testing Of Modddels
    • Unit-Testing Overview
    • Available Tests
    • Customizing Tests
  • Additional Information
    • Using type aliases
    • Re-running the generator
    • All Available Modddels
    • VsCode Snippets
Powered by GitBook
On this page
  1. Advanced Notions

Using multiple parameters annotations

PreviousThe NullFailure AnnotationNextClass Hierarchy of ValueObjects

Here is a list of all the parameters annotations and where you can use them :

Annotation
Parameter kind
Modddel kind

@withGetter

Member parameter

Any modddel

@validParam

Member parameter

SimpleEntity

@invalidParam

Member parameter

SimpleEntity

@NullFailure

Member parameter

Any modddel

@dependencyParam

Dependency parameter

Any modddel

You can annotate the same parameter with multiple annotations :

  • You can use @withGetter with any other member parameter annotation

  • You can use @NullFailure with @validParam

  • For Iterable2Entity, the member parameter can have up to two @NullFailure annotations, one for each maskNb

However :

  • You can't use @dependencyParam with any annotation reserved to member parameters

  • You can't use @NullFailure with @invalidParam : That's because @invalidParam requires a nullable parameter that is valid when it's null . If you want an alternative, .

  • You can't use @validParam with @invalidParam

Example :

factory Person({
  @withGetter @NullFailure('identity', PersonIdentityFailure.unnamed()) required FullName? name,
  required Age age,
  @validParam @withGetter bool isAdult,
  @dependencyParam AvailabilityService availabilityService,
})

If you want to use both @validParam and @withGetter, you can use the shorthand @validWithGetter. Similarly, if you want to use both @invalidParam and @withGetter, you can use the shorthand @invalidWithGetter.

factory FreeArticle({
    // Same as @validParam @withGetter
    @validWithGetter required String id,
    required Description description,
    // Same as @invalidParam @withGetter
    @invalidWithGetter required InvalidPrice? price,
  }) { ...
(See relevant section)
see this section