|
31 | 31 | import java.util.Properties;
|
32 | 32 |
|
33 | 33 | /**
|
| 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. |
34 | 44 | *
|
35 | 45 | */
|
36 | 46 | public class App {
|
37 | 47 |
|
38 | 48 | /**
|
| 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. |
39 | 60 | *
|
| 61 | + * @see User |
| 62 | + * @see UserGroup |
| 63 | + * @see Service |
| 64 | + * @see PropertiesFeatureToggleVersion |
| 65 | + * @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion; |
40 | 66 | */
|
41 | 67 | public static void main(String[] args) {
|
| 68 | + |
42 | 69 | final Properties properties = new Properties();
|
43 | 70 | properties.put("enhancedWelcome", true);
|
44 | 71 | Service service = new PropertiesFeatureToggleVersion(properties);
|
45 | 72 | final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
|
46 | 73 | System.out.println(welcomeMessage);
|
47 | 74 |
|
| 75 | + // --------------------------------------------- |
| 76 | + |
48 | 77 | final Properties turnedOff = new Properties();
|
49 | 78 | turnedOff.put("enhancedWelcome", false);
|
50 | 79 | Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
|
51 | 80 | final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
|
52 | 81 | System.out.println(welcomeMessageturnedOff);
|
53 | 82 |
|
| 83 | + // -------------------------------------------- |
| 84 | + |
54 | 85 | final User paidUser = new User("Jamie Coder");
|
55 | 86 | final User freeUser = new User("Alan Defect");
|
56 | 87 |
|
|
0 commit comments