ValueObject<Failure, T> class
abstract
Extend this abstract class to create a validated value object class.
A value object is an object that contains attributes, but has no conceptual identity.
class RequiredString extends ValueObject<String, String> {
final Either<String, String> value;
factory RequiredString(String input) {
assert(input != null);
if (input.isNotEmpty) {
return RequiredString._(right(input));
} else {
return RequiredString._(left('Value must not be empty'));
}
}
RequiredString._(this.value);
}
- Annotations
-
- @immutable
Constructors
- ValueObject()
-
Creates a ValueObject
const
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- isValid → bool
-
True if this is valid.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
value
→ Either<
Failure, T> -
The value of this ValueObject
no setter
Methods
-
getOrCrash(
) → T - If this is valid, returns the value. Otherwise, throws UnexpectedValueError.
-
getOrElse(
T dflt) → T -
If this is valid, returns the value. Otherwise, returns
dflt
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object o) → bool -
The equality operator.
override