You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: feature-toggle/README.md
+49-28Lines changed: 49 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -3,38 +3,39 @@ title: Feature Toggle
3
3
category: Behavioral
4
4
language: en
5
5
tag:
6
-
- Extensibility
6
+
- Decoupling
7
+
- Extensibility
8
+
- Feature management
9
+
- Scalability
7
10
---
8
11
9
12
## Also known as
10
-
Feature Flag
13
+
14
+
* Feature Flag
15
+
* Feature Switch
11
16
12
17
## Intent
13
-
A technique used in software development to control and manage the rollout of specific features or functionality in a
14
-
program without changing the code. It can act as an on/off switch for features depending on the status or properties of
15
-
other values in the program. This is similar to A/B testing, where features are rolled out based on properties such as
16
-
location or device. Implementing this design pattern can increase code complexity, and it is important to remember to
17
-
remove redundant code if this design pattern is being used to phase out a system or feature.
18
+
19
+
A technique used in software development to control and manage the rollout of specific features or functionality in a program without changing the code. It can act as an on/off switch for features depending on the status or properties of other values in the program. This is similar to A/B testing, where features are rolled out based on properties such as location or device. Implementing this design pattern can increase code complexity, and it is important to remember to remove redundant code if this design pattern is being used to phase out a system or feature.
18
20
19
21
## Explanation
22
+
20
23
Real-world Example
21
-
> This design pattern works really well in any sort of development, in particular mobile development. Say you want to
22
-
> introduce a feature such as dark mode, but you want to ensure that the feature works correctly and don't want to roll
23
-
> out the feature to everyone immediately. You write in the code, and have it switched off as default. From here, it is
24
-
> easy to turn on the code for specific users based on selection criteria, or randomly. This will also allow the feature
25
-
> to be turned off easily without any drastic changes to the code, or any need for redeployment or updates.
24
+
25
+
> This design pattern works really well in any sort of development, in particular mobile development. Say you want to introduce a feature such as dark mode, but you want to ensure that the feature works correctly and don't want to roll out the feature to everyone immediately. You write in the code, and have it switched off as default. From here, it is easy to turn on the code for specific users based on selection criteria, or randomly. This will also allow the feature to be turned off easily without any drastic changes to the code, or any need for redeployment or updates.
26
26
27
27
In plain words
28
+
28
29
> Feature Toggle is a way to introduce new features gradually instead of deployment all at once.
29
30
30
31
Wikipedia says
31
-
> A feature toggle in software development provides an alternative to maintaining multiple feature branches in source
32
-
> code. A condition within the code enables or disables a feature during runtime. In agile settings the toggle is
33
-
> used in production, to switch on the feature on demand, for some or all the users.
32
+
33
+
> A feature toggle in software development provides an alternative to maintaining multiple feature branches in source code. A condition within the code enables or disables a feature during runtime. In agile settings the toggle is used in production, to switch on the feature on demand, for some or all the users.
34
34
35
35
## Programmatic Example
36
-
This example shows Java code that allows a feature to show when it is enabled by the developer, and when a user is a
37
-
Premium member of the application. This is useful for subscription locked features.
36
+
37
+
This example shows Java code that allows a feature to show when it is enabled by the developer, and when a user is a Premium member of the application. This is useful for subscription locked features.
38
+
38
39
```java
39
40
publicclassFeatureToggleExample {
40
41
// Bool for feature enabled or disabled
@@ -55,32 +56,52 @@ public class FeatureToggleExample {
55
56
}
56
57
}
57
58
```
58
-
The code shows how simple it is to implement this design pattern, and the criteria can be further refined or broadened
59
-
should the developers choose to do so.
59
+
60
+
The code shows how simple it is to implement this design pattern, and the criteria can be further refined or broadened should the developers choose to do so.
*Conditional feature access to different users and groups.
68
71
* Rolling out a new feature incrementally.
69
72
* Switching between development and production environments.
70
73
* Quickly disable problematic features
71
74
* External management of feature deployment
72
75
* Ability to maintain multiple version releases of a feature
73
76
* 'Hidden' deployment, releasing a feature in code for designated testing but not publicly making it available
74
77
78
+
## Known Uses
79
+
80
+
* Web development platforms use feature toggles to gradually roll out new features to users to ensure stability.
81
+
* Enterprise applications use feature toggles to enable or disable features during runtime to cater to different market needs.
82
+
75
83
## Consequences
76
-
Consequences involved with using the Feature Toggle pattern
77
84
78
-
* Code complexity is increased
79
-
* Testing of multiple states is harder and more time-consuming
80
-
* Confusion between friends on why features are missing
81
-
* Keeping documentation up to date with all features can be difficult
85
+
Benefits:
86
+
87
+
* Facilitates A/B testing and canary releases.
88
+
* Allows for quicker rollback and minimal risk deployments.
89
+
* Enables conditional feature execution without redeploying the application.
90
+
91
+
Trade-offs:
92
+
93
+
* Code complexity is increased.
94
+
* Testing of multiple states is harder and more time-consuming.
95
+
* Potential for technical debt if toggles remain in the code longer than necessary.
96
+
* Risk of toggle misconfiguration leading to unexpected behavior.
97
+
98
+
## Related Patterns
99
+
100
+
*[Strategy](https://java-design-patterns.com/patterns/strategy/): Both patterns allow changing the behavior of software at runtime. The Feature Toggle changes features dynamically, while the Strategy allows switching algorithms or strategies.
101
+
*[Observer](https://java-design-patterns.com/patterns/observer/): Useful for implementing feature toggles by notifying components of feature state changes, which allows dynamic feature modification without restarts.
82
102
83
103
## Credits
84
104
85
-
*[Martin Fowler 29 October 2010 (2010-10-29).](http://martinfowler.com/bliki/FeatureToggle.html)
Copy file name to clipboardExpand all lines: feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersion.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -77,12 +77,12 @@ public PropertiesFeatureToggleVersion(final Properties properties) {
77
77
/**
78
78
* Generate a welcome message based on the user being passed and the status of the feature toggle.
79
79
* If the enhanced version is enabled, then the message will be personalised with the name of the
80
-
* passed {@link User}. However if disabled then a generic version fo the message is returned.
80
+
* passed {@link User}. However, if disabled then a generic version fo the message is returned.
81
81
*
82
82
* @param user the {@link User} to be displayed in the message if the enhanced version is enabled
83
83
* see {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is
84
84
* enabled, then the message will be personalised with the name of the passed {@link
85
-
* User}. However if disabled then a generic version fo the message is returned.
85
+
* User}. However, if disabled then a generic version fo the message is returned.
Copy file name to clipboardExpand all lines: feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersion.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -30,10 +30,10 @@
30
30
31
31
/**
32
32
* This example of the Feature Toggle pattern shows how it could be implemented based on a {@link
33
-
* User}. Therefore showing its use within a tiered application where the paying users get access to
33
+
* User}. Therefore, showing its use within a tiered application where the paying users get access to
34
34
* different content or better versions of features. So in this instance a {@link User} is passed in
35
35
* and if they are found to be on the {@link UserGroup#isPaid(User)} they are welcomed with a
36
-
* personalised message. While the other is more generic. However this pattern is limited to simple
36
+
* personalised message. While the other is more generic. However, this pattern is limited to simple
37
37
* examples such as the one below.
38
38
*
39
39
* @see Service
@@ -66,7 +66,7 @@ public String getWelcomeMessage(User user) {
66
66
67
67
/**
68
68
* Method that checks if the welcome message to be returned is the enhanced version. For this
69
-
* instance as the logic is driven by the user group. This method is a little redundant. However
69
+
* instance as the logic is driven by the user group. This method is a little redundant. However,
70
70
* can be used to show that there is an enhanced version available.
Copy file name to clipboardExpand all lines: feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java
+1-3Lines changed: 1 addition & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -40,9 +40,7 @@ class PropertiesFeatureToggleVersionTest {
0 commit comments