Feature
Represents a feature flag (feature toggle) identified by a unique identifier.
Feature flags enable/disable functionality at runtime, supporting continuous delivery and controlled feature rollouts as introduced by Martin Fowler.
Core Capabilities
Runtime Control: Enable or disable features without code changes or redeployment
Security Management: Limit feature access to specific user roles/permissions
Grouping: Organize features into groups for bulk operations
Advanced Strategies: Use FlippingStrategy for A/B testing, gradual rollouts, etc.
Custom Properties: Attach metadata and configuration to features
Immutability
This class is immutable by design. All state-changing operations (enable, disable, toggle, addProperty) return a new Feature instance rather than modifying the current one.
Example usage:
val feature = Feature(
uid = "new-checkout-flow",
isEnabled = true,
description = "New streamlined checkout process",
group = "checkout",
permissions = setOf("BETA_TESTERS", "ADMIN")
)
// State changes return new instances
val disabled = feature.disable()
val toggled = feature.toggle()
// Add custom properties
val withProperty = feature.addProperty(
intProperty("maxRetries") {
value = 3
}
)Throws
Constructors
Properties
Custom properties attached to this feature.
Optional human-readable description of this feature.
The simple class name of the flippingStrategy, or null if no strategy is set.
Optional strategy for advanced feature activation logic.
Checks if this feature has a flipping strategy configured.
Checks if this feature has any permission restrictions.
Checks if this feature is disabled.
Set of roles or permissions required to access this feature.
Returns the set of all custom property names attached to this feature.
Functions
Returns a new Feature with multiple properties added.
Returns a new Feature instance with the given property added to customProperties.
Returns a new Feature with all permissions removed.
Returns a new Feature with all custom properties removed.
Retrieves a custom property by name.
Returns a new Feature with the specified permissions granted.
Checks if this feature has all of the specified permissions.
Checks if this feature has at least one of the specified permissions.
Returns a new Feature removed from its current group.
Returns a new Feature with the specified properties removed.
Returns a new Feature with the specified permissions revoked.