An abstract interface for managing name aliases in a registry system.
The AliasRegistry provides a contract for classes that need to manage alternative names (aliases) for registered objects. This is particularly useful in dependency injection systems, configuration management, or any scenario where objects need to be accessible by multiple names.
Key Features:
- Register alternative names for existing entries
- Remove aliases when they are no longer needed
- Check if a given name is an alias
- Retrieve all aliases for a specific name
Implementation Notes:
Implementations should ensure that:
- Aliases cannot conflict with existing primary names
- Circular alias references are handled appropriately
- Alias management is thread-safe if used in concurrent environments
Usage Example:
class MyAliasRegistry implements AliasRegistry {
final _aliases = <String, String>{};
final _reverseMap = <String, List<String>>{};
@override
void registerAlias(String name, String alias) {
if (_aliases.containsKey(alias)) {
throw InvalidArgumentException('Alias $alias already exists');
}
_aliases[alias] = name;
_reverseMap.putIfAbsent(name, () => []).add(alias);
}
// ... other method implementations
}
void main() {
final registry = MyAliasRegistry();
// Register a service with its primary name and aliases
registry.registerAlias('databaseService', 'db');
registry.registerAlias('databaseService', 'dataSource');
print(registry.isAlias('db')); // true
print(registry.isAlias('databaseService')); // false
print(registry.getAliases('databaseService')); // ['db', 'dataSource']
}
- Implemented types
- Implementers
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
-
getAlias(
String name) → String? -
Retrieves the primary name associated with the given
alias. -
getAliases(
String name) → List< String> -
Retrieves all aliases registered for the given primary
name. -
isAlias(
String name) → bool -
Checks whether the given
nameis registered as an alias. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerAlias(
String name, String alias) → void -
Registers an alias for an existing name in the registry.
inherited
-
removeAlias(
String alias) → void - Removes an alias from the registry.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited