Mergeable class abstract

Interface for objects that can merge with other objects of the same type.

This interface defines a contract for objects that support intelligent merging operations, where properties from a parent object are combined with the current object's properties in a non-destructive way.

Merging is used extensively in configuration scenarios where:

  • Child configurations inherit from parent configurations
  • Default values are combined with override values
  • Multiple configuration sources need to be combined

Example usage:

class Config implements Mergeable {
  final Map<String, dynamic> values;

  Config(this.values);

  @override
  bool isMergeEnabled() => true;

  @override
  Object merge(Object parent) {
    if (parent is Config) {
      return Config({...parent.values, ...values});
    }
    return this;
  }
}

final parentConfig = Config({'timeout': 5000, 'host': 'localhost'});
final childConfig = Config({'timeout': 10000, 'port': 8080});
final merged = childConfig.merge(parentConfig) as Config;
print(merged.values); // {'timeout': 10000, 'host': 'localhost', 'port': 8080}

Constructors

Mergeable()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

isMergeEnabled() bool
Returns whether merging is enabled for this particular instance.
merge(Object parent) Object
Merge the current value set with that of the supplied object.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited