Skip to content

Commit c7f4311

Browse files
committed
iluwatar#354 Clean up
1 parent 37da470 commit c7f4311

File tree

1 file changed

+31
-0
lines changed
  • feature-toggle/src/main/java/com/iluwatar/featuretoggle

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,57 @@
3131
import java.util.Properties;
3232

3333
/**
34+
* The Feature Toggle pattern allows for complete code executions to be turned on or off with ease. This allows features
35+
* to be controlled by either dynamic methods just as {@link User} information or by {@link Properties}. In the App
36+
* below there are two examples. Firstly the {@link Properties} version of the feature toggle, where the enhanced
37+
* version of the welcome message which is personalised is turned either on or off at instance creation. This method
38+
* is not as dynamic as the {@link User} driven version where the feature of the personalised welcome message is
39+
* dependant on the {@link UserGroup} the {@link User} is in. So if the user is a memeber of the
40+
* {@link UserGroup#isPaid(User)} then they get an ehanced version of the welcome message.
41+
*
42+
* Note that this pattern can easily introduce code complexity, and if not kept in check can result in redundant
43+
* unmaintained code within the codebase.
3444
*
3545
*/
3646
public class App {
3747

3848
/**
49+
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
50+
* toggle to enabled.
51+
*
52+
* Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
53+
* toggle to disabled. Notice the difference with the printed welcome message the username is not included.
54+
*
55+
* Block 3 shows the {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} being
56+
* set up with two users on who is on the free level, while the other is on the paid level. When the
57+
* {@link Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome message
58+
* contains their username, while the same service call with the free tier user is more generic. No username is
59+
* printed.
3960
*
61+
* @see User
62+
* @see UserGroup
63+
* @see Service
64+
* @see PropertiesFeatureToggleVersion
65+
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion;
4066
*/
4167
public static void main(String[] args) {
68+
4269
final Properties properties = new Properties();
4370
properties.put("enhancedWelcome", true);
4471
Service service = new PropertiesFeatureToggleVersion(properties);
4572
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
4673
System.out.println(welcomeMessage);
4774

75+
// ---------------------------------------------
76+
4877
final Properties turnedOff = new Properties();
4978
turnedOff.put("enhancedWelcome", false);
5079
Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
5180
final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
5281
System.out.println(welcomeMessageturnedOff);
5382

83+
// --------------------------------------------
84+
5485
final User paidUser = new User("Jamie Coder");
5586
final User freeUser = new User("Alan Defect");
5687

0 commit comments

Comments
 (0)