zorphy top-level constant

Zorphy const zorphy

normal class; prepend class with a single dollar & make abstract

abstract class $MyClass { ...

define non final get properties only (no constructor)

String get aValue;
int? get nullableValue;

to instantiate or use the class omit the dollar

MyClass(aValue: "x");

to implement an interface use implements

@zorphy
abstract class $B implements $$A<int, String> {
 String get z;

to inherit from a base class use extends (issue #109)

@Zorphy(kind: ZorphyKind.valueObject)
abstract class $Base { String get x; }

@Zorphy(kind: ZorphyKind.valueObject)
abstract class $Sub extends $Base {
  String get y;
}

The generated concrete class will extends Base — proper Dart inheritance. The subclass inherits the base's fields, copyWith, equality, JSON, etc., and only redeclares its own fields. Use this when the abstract subclass should be a base (isA() holds at runtime), not merely satisfy its interface.

ensure the generic names are the same between inherited classes

class $A<T1> { ...
class $B<T1> extends $A<T1> { ...

abstract classes; prepend class with two dollars

class $$myAbstractClass { ...

private constructor for custom constructors; postpend with underscore

abstract class $A_ {

this then allows default values by defining custom functions in the same file

A_ AFactory() {
   return A_._(a: "my default value");
}

it makes it explict that the default constructor cannot be used

constant constructors

abstract class $A {
 int get a;
 const $A();
 }

must add a const $A() constructor to abstract class

Implementation

const zorphy = Zorphy();