Skip to content

Commit 37da470

Browse files
committed
iluwatar#354 Finish Readme
1 parent b27d6df commit 37da470

File tree

10 files changed

+82
-32
lines changed

10 files changed

+82
-32
lines changed

feature-toggle/index.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: pattern
3+
title: Feature Toggle
4+
folder: feature-toggle
5+
permalink: /patterns/feature-toggle/
6+
categories: Behavioral
7+
tags:
8+
- Java
9+
- Difficulty-Beginner
10+
---
11+
12+
## Also known as
13+
Feature Flag
14+
15+
## Intent
16+
Used to switch code execution paths based on properties or groupings. Allowing new features to be released, tested
17+
and rolled out. Allowing switching back to the older feature quickly if needed. It should be noted that this pattern,
18+
can easily introduce code complexity. There is also cause for concern that the old feature that the toggle is eventually
19+
going to phase out is never removed, causing redundant code smells and increased maintainability.
20+
21+
![alt text](./etc/feature-toggle.png "Feature Toggle")
22+
23+
## Applicability
24+
Use the Feature Toogle pattern when
25+
26+
* Giving different features to different users.
27+
* Rolling out a new feature incrementally.
28+
* Switching between development and production environments.
29+
30+
## Credits
31+
32+
* [Martin Fowler 29 October 2010 (2010-10-29).](http://martinfowler.com/bliki/FeatureToggle.html)

feature-toggle/src/main/java/com/iluwatar/featuretoggle/App.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/Service.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersion.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -28,7 +28,16 @@
2828
import java.util.Properties;
2929

3030
/**
31+
* This example of the Feature Toogle pattern is less dynamic version than
32+
* {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the feature is turned on
33+
* or off at the time of creation of the service. This example uses simple Java {@link Properties} however it could as
34+
* easily be done with an external configuration file loaded by Spring and so on. A good example of when to use this
35+
* version of the feature toggle is when new features are being developed. So you could have a configuration property
36+
* boolean named development or some sort of system environment variable.
3137
*
38+
* @see Service
39+
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
40+
* @see User
3241
*/
3342
public class PropertiesFeatureToggleVersion implements Service {
3443

feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersion.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -27,7 +27,16 @@
2727
import com.iluwatar.featuretoggle.user.UserGroup;
2828

2929
/**
30+
* This example of the Feature Toogle pattern shows how it could be implemented based on a {@link User}. Therefore
31+
* showing its use within a tiered application where the paying users get access to different content or
32+
* better versions of features. So in this instance a {@link User} is passed in and if they are found to be
33+
* on the {@link UserGroup#isPaid(User)} they are welcomed with a personalised message. While the other is more
34+
* generic. However this pattern is limited to simple examples such as the one below.
3035
*
36+
* @see Service
37+
* @see User
38+
* @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion
39+
* @see UserGroup
3140
*/
3241
public class TieredFeatureToggleVersion implements Service {
3342

feature-toggle/src/main/java/com/iluwatar/featuretoggle/user/User.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

feature-toggle/src/main/java/com/iluwatar/featuretoggle/user/UserGroup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersionTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -43,27 +43,27 @@ public void testNullPropertiesPassed() throws Exception {
4343
@Test(expected = IllegalArgumentException.class)
4444
public void testNonBooleanProperty() throws Exception {
4545
final Properties properties = new Properties();
46-
properties.setProperty("enhancedWelcome","Something");
46+
properties.setProperty("enhancedWelcome", "Something");
4747
new PropertiesFeatureToggleVersion(properties);
4848
}
4949

5050
@Test
5151
public void testFeatureTurnedOn() throws Exception {
5252
final Properties properties = new Properties();
53-
properties.put("enhancedWelcome",true);
53+
properties.put("enhancedWelcome", true);
5454
Service service = new PropertiesFeatureToggleVersion(properties);
5555
assertTrue(service.isEnhanced());
5656
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
57-
assertEquals("Welcome Jamie No Code. You're using the enhanced welcome message.",welcomeMessage);
57+
assertEquals("Welcome Jamie No Code. You're using the enhanced welcome message.", welcomeMessage);
5858
}
5959

6060
@Test
6161
public void testFeatureTurnedOff() throws Exception {
6262
final Properties properties = new Properties();
63-
properties.put("enhancedWelcome",false);
63+
properties.put("enhancedWelcome", false);
6464
Service service = new PropertiesFeatureToggleVersion(properties);
6565
assertFalse(service.isEnhanced());
6666
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
67-
assertEquals("Welcome to the application.",welcomeMessage);
67+
assertEquals("Welcome to the application.", welcomeMessage);
6868
}
6969
}

feature-toggle/src/test/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

feature-toggle/src/test/java/com/iluwatar/featuretoggle/user/UserGroupTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2014 Ilkka Seppälä
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

0 commit comments

Comments
 (0)