Merge remote-tracking branch 'upstream/master'

This commit is contained in:
JuhoKang 2016-02-03 22:49:59 +09:00
commit 1e5cbe1f76
94 changed files with 953 additions and 86 deletions

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>abstract-factory</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>adapter</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>async-method-invocation</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>bridge</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>builder</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>business-delegate</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>caching</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>callback</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>chain</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>command</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>composite</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>dao</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>decorator</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>dependency-injection</artifactId>
<dependencies>

View File

@ -27,7 +27,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>double-checked-locking</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>double-dispatch</artifactId>
<dependencies>

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>event-aggregator</artifactId>
<dependencies>

View File

@ -31,7 +31,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>event-driven-architecture</artifactId>

View File

@ -23,5 +23,5 @@ Use the Execute Around idiom when
* you use an API that requires methods to be called in pairs such as open/close or allocate/deallocate.
##Credits
## Credits
* [Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions](http://www.amazon.com/Functional-Programming-Java-Harnessing-Expressions/dp/1937785467/ref=sr_1_1)

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>execute-around</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>facade</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>factory-method</artifactId>
<dependencies>

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="true" generalizations="true"
realizations="true" associations="true" dependencies="true" nesting-relationships="true" router="FAN">
<interface id="1" language="java" name="com.iluwatar.featuretoggle.pattern.Service" project="feature-toggle"
file="/feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/Service.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="238" y="187"/>
<display autosize="true" stereotype="true" package="true" initial-value="true" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="2" language="java"
name="com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion" project="feature-toggle"
file="/feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/propertiesversion/PropertiesFeatureToggleVersion.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="241" y="449"/>
<display autosize="true" stereotype="true" package="true" initial-value="true" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion"
project="feature-toggle"
file="/feature-toggle/src/main/java/com/iluwatar/featuretoggle/pattern/tieredversion/TieredFeatureToggleVersion.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="149" width="230" x="502" y="119"/>
<display autosize="false" stereotype="true" package="true" initial-value="true" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="com.iluwatar.featuretoggle.user.User" project="feature-toggle"
file="/feature-toggle/src/main/java/com/iluwatar/featuretoggle/user/User.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="616" y="453"/>
<display autosize="true" stereotype="true" package="true" initial-value="true" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="5" language="java" name="com.iluwatar.featuretoggle.user.UserGroup" project="feature-toggle"
file="/feature-toggle/src/main/java/com/iluwatar/featuretoggle/user/UserGroup.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="956" y="187"/>
<display autosize="true" stereotype="true" package="true" initial-value="true" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<dependency id="6">
<end type="SOURCE" refId="1"/>
<end type="TARGET" refId="4"/>
</dependency>
<dependency id="7">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="5"/>
</dependency>
<association id="8">
<bendpoint x="911" y="415"/>
<end type="SOURCE" refId="5" navigable="false">
<attribute id="9" name="freeGroup">
<position height="19" width="63" x="846" y="368"/>
</attribute>
<multiplicity id="10" minimum="0" maximum="2147483647">
<position height="17" width="23" x="707" y="418"/>
</multiplicity>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="11">
<end type="SOURCE" refId="2"/>
<end type="TARGET" refId="1"/>
</realization>
<dependency id="12">
<end type="SOURCE" refId="2"/>
<end type="TARGET" refId="4"/>
</dependency>
<dependency id="13">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="4"/>
</dependency>
<association id="14">
<bendpoint x="953" y="459"/>
<end type="SOURCE" refId="5" navigable="false">
<attribute id="15" name="paidGroup">
<position height="19" width="66" x="963" y="419"/>
</attribute>
<multiplicity id="16" minimum="0" maximum="2147483647">
<position height="17" width="23" x="711" y="463"/>
</multiplicity>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="17">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="1"/>
</realization>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="true" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

32
feature-toggle/index.md Normal file
View File

@ -0,0 +1,32 @@
---
layout: pattern
title: Feature Toggle
folder: feature-toggle
permalink: /patterns/feature-toggle/
categories: Behavioral
tags:
- Java
- Difficulty-Beginner
---
## Also known as
Feature Flag
## Intent
Used to switch code execution paths based on properties or groupings. Allowing new features to be released, tested
and rolled out. Allowing switching back to the older feature quickly if needed. It should be noted that this pattern,
can easily introduce code complexity. There is also cause for concern that the old feature that the toggle is eventually
going to phase out is never removed, causing redundant code smells and increased maintainability.
![alt text](./etc/feature-toggle.png "Feature Toggle")
## Applicability
Use the Feature Toogle pattern when
* Giving different features to different users.
* Rolling out a new feature incrementally.
* Switching between development and production environments.
## Credits
* [Martin Fowler 29 October 2010 (2010-10-29).](http://martinfowler.com/bliki/FeatureToggle.html)

48
feature-toggle/pom.xml Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright (c) 2014 Ilkka Seppälä
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.11.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feature-toggle</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,96 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle;
import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion;
import com.iluwatar.featuretoggle.user.User;
import com.iluwatar.featuretoggle.user.UserGroup;
import java.util.Properties;
/**
* The Feature Toggle pattern allows for complete code executions to be turned on or off with ease. This allows features
* to be controlled by either dynamic methods just as {@link User} information or by {@link Properties}. In the App
* below there are two examples. Firstly the {@link Properties} version of the feature toggle, where the enhanced
* version of the welcome message which is personalised is turned either on or off at instance creation. This method
* is not as dynamic as the {@link User} driven version where the feature of the personalised welcome message is
* dependant on the {@link UserGroup} the {@link User} is in. So if the user is a memeber of the
* {@link UserGroup#isPaid(User)} then they get an ehanced version of the welcome message.
*
* Note that this pattern can easily introduce code complexity, and if not kept in check can result in redundant
* unmaintained code within the codebase.
*
*/
public class App {
/**
* Block 1 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
* toggle to enabled.
*
* Block 2 shows the {@link PropertiesFeatureToggleVersion} being run with {@link Properties} setting the feature
* toggle to disabled. Notice the difference with the printed welcome message the username is not included.
*
* Block 3 shows the {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} being
* set up with two users on who is on the free level, while the other is on the paid level. When the
* {@link Service#getWelcomeMessage(User)} is called with the paid {@link User} note that the welcome message
* contains their username, while the same service call with the free tier user is more generic. No username is
* printed.
*
* @see User
* @see UserGroup
* @see Service
* @see PropertiesFeatureToggleVersion
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion;
*/
public static void main(String[] args) {
final Properties properties = new Properties();
properties.put("enhancedWelcome", true);
Service service = new PropertiesFeatureToggleVersion(properties);
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
System.out.println(welcomeMessage);
// ---------------------------------------------
final Properties turnedOff = new Properties();
turnedOff.put("enhancedWelcome", false);
Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
System.out.println(welcomeMessageturnedOff);
// --------------------------------------------
final User paidUser = new User("Jamie Coder");
final User freeUser = new User("Alan Defect");
UserGroup.addUserToPaidGroup(paidUser);
UserGroup.addUserToFreeGroup(freeUser);
final String welcomeMessagePaidUser = service.getWelcomeMessage(paidUser);
final String welcomeMessageFreeUser = service.getWelcomeMessage(freeUser);
System.out.println(welcomeMessageFreeUser);
System.out.println(welcomeMessagePaidUser);
}
}

View File

@ -0,0 +1,54 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.pattern;
import com.iluwatar.featuretoggle.user.User;
/**
* Simple interfaces to allow the calling of the method to generate the welcome message for a given user. While there is
* a helper method to gather the the status of the feature toggle. In some cases there is no need for the
* {@link Service#isEnhanced()} in {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion}
* where the toggle is determined by the actual {@link User}.
*
* @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
* @see User
*/
public interface Service {
/**
* Generates a welcome message for the passed user.
*
* @param user the {@link User} to be used if the message is to be personalised.
* @return Generated {@link String} welcome message
*/
String getWelcomeMessage(User user);
/**
* Returns if the welcome message to be displayed will be the enhanced version.
*
* @return Boolean {@value true} if enhanced.
*/
boolean isEnhanced();
}

View File

@ -0,0 +1,100 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.pattern.propertiesversion;
import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.user.User;
import java.util.Properties;
/**
* This example of the Feature Toogle pattern is less dynamic version than
* {@link com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the feature is turned on
* or off at the time of creation of the service. This example uses simple Java {@link Properties} however it could as
* easily be done with an external configuration file loaded by Spring and so on. A good example of when to use this
* version of the feature toggle is when new features are being developed. So you could have a configuration property
* boolean named development or some sort of system environment variable.
*
* @see Service
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
* @see User
*/
public class PropertiesFeatureToggleVersion implements Service {
private boolean isEnhanced;
/**
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link Properties} to determine,
* the status of the feature toggle {@link PropertiesFeatureToggleVersion#isEnhanced()}. There is also some defensive
* code to ensure the {@link Properties} passed are as expected.
*
* @param properties {@link Properties} used to configure the service and toggle features.
* @throws IllegalArgumentException when the passed {@link Properties} is not as expected
* @see Properties
*/
public PropertiesFeatureToggleVersion(final Properties properties) {
if (properties == null) {
throw new IllegalArgumentException("No Properties Provided.");
} else {
try {
isEnhanced = (boolean) properties.get("enhancedWelcome");
} catch (Exception e) {
throw new IllegalArgumentException("Invalid Enhancement Settings Provided.");
}
}
}
/**
* Generate a welcome message based on the user being passed and the status of the feature toggle. If the enhanced
* version is enabled, then the message will be personalised with the name of the passed {@link User}. However if
* disabled then a generic version fo the message is returned.
*
* @param user the {@link User} to be displayed in the message if the enhanced version is enabled see
* {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is enabled, then the
* message will be personalised with the name of the passed {@link User}. However if disabled then a
* generic version fo the message is returned.
* @return Resulting welcome message.
* @see User
*/
@Override
public String getWelcomeMessage(final User user) {
if (isEnhanced()) {
return "Welcome " + user + ". You're using the enhanced welcome message.";
}
return "Welcome to the application.";
}
/**
* Method that checks if the welcome message to be returned is the enhanced venison or not. For this service it will
* see the value of the boolean that was set in the constructor
* {@link PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
*
* @return Boolean value {@value true} if enhanced.
*/
@Override
public boolean isEnhanced() {
return isEnhanced;
}
}

View File

@ -0,0 +1,75 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.pattern.tieredversion;
import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.user.User;
import com.iluwatar.featuretoggle.user.UserGroup;
/**
* This example of the Feature Toogle pattern shows how it could be implemented based on a {@link User}. Therefore
* showing its use within a tiered application where the paying users get access to different content or
* better versions of features. So in this instance a {@link User} is passed in and if they are found to be
* on the {@link UserGroup#isPaid(User)} they are welcomed with a personalised message. While the other is more
* generic. However this pattern is limited to simple examples such as the one below.
*
* @see Service
* @see User
* @see com.iluwatar.featuretoggle.pattern.propertiesversion.PropertiesFeatureToggleVersion
* @see UserGroup
*/
public class TieredFeatureToggleVersion implements Service {
/**
* Generates a welcome message from the passed {@link User}. The resulting message depends on the group of the
* {@link User}. So if the {@link User} is in the {@link UserGroup#paidGroup} then the enhanced version of the
* welcome message will be returned where the username is displayed.
*
* @param user the {@link User} to generate the welcome message for, different messages are displayed if the user is
* in the {@link UserGroup#isPaid(User)} or {@link UserGroup#freeGroup}
* @return Resulting welcome message.
* @see User
* @see UserGroup
*/
@Override
public String getWelcomeMessage(User user) {
if (UserGroup.isPaid(user)) {
return "You're amazing " + user + ". Thanks for paying for this awesome software.";
}
return "I suppose you can use this software.";
}
/**
* Method that checks if the welcome message to be returned is the enhanced version. For this instance as the logic
* is driven by the user group. This method is a little redundant. However can be used to show that there is an
* enhanced version available.
*
* @return Boolean value {@value true} if enhanced.
*/
@Override
public boolean isEnhanced() {
return true;
}
}

View File

@ -0,0 +1,49 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.user;
/**
* Used to demonstrate the purpose of the feature toggle. This class actually has nothing to do with the pattern.
*/
public class User {
private String name;
/**
* Default Constructor setting the username.
*
* @param name {@link String} to represent the name of the user.
*/
public User(String name) {
this.name = name;
}
/**
* {@inheritDoc}
* @return The {@link String} representation of the User, in this case just return the name of the user.
*/
@Override
public String toString() {
return name;
}
}

View File

@ -0,0 +1,84 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.user;
import java.util.ArrayList;
import java.util.List;
/**
* Contains the lists of users of different groups paid and free. Used to demonstrate the tiered example of feature
* toggle. Allowing certain features to be available to only certain groups of users.
*
* @see User
*/
public class UserGroup {
private static List<User> freeGroup = new ArrayList<>();
private static List<User> paidGroup = new ArrayList<>();
/**
* Add the passed {@link User} to the free user group list.
*
* @param user {@link User} to be added to the free group
* @throws IllegalArgumentException when user is already added to the paid group
* @see User
*/
public static void addUserToFreeGroup(final User user) throws IllegalArgumentException {
if (paidGroup.contains(user)) {
throw new IllegalArgumentException("User all ready member of paid group.");
} else {
if (!freeGroup.contains(user)) {
freeGroup.add(user);
}
}
}
/**
* Add the passed {@link User} to the paid user group list.
*
* @param user {@link User} to be added to the paid group
* @throws IllegalArgumentException when the user is already added to the free group
* @see User
*/
public static void addUserToPaidGroup(final User user) throws IllegalArgumentException {
if (freeGroup.contains(user)) {
throw new IllegalArgumentException("User all ready member of free group.");
} else {
if (!paidGroup.contains(user)) {
paidGroup.add(user);
}
}
}
/**
* Method to take a {@link User} to determine if the user is in the {@link UserGroup#paidGroup}.
*
* @param user {@link User} to check if they are in the {@link UserGroup#paidGroup}
*
* @return true if the {@link User} is in {@link UserGroup#paidGroup}
*/
public static boolean isPaid(User user) {
return paidGroup.contains(user);
}
}

View File

@ -0,0 +1,69 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.pattern.propertiesversion;
import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.user.User;
import org.junit.Test;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class PropertiesFeatureToggleVersionTest {
@Test(expected = IllegalArgumentException.class)
public void testNullPropertiesPassed() throws Exception {
new PropertiesFeatureToggleVersion(null);
}
@Test(expected = IllegalArgumentException.class)
public void testNonBooleanProperty() throws Exception {
final Properties properties = new Properties();
properties.setProperty("enhancedWelcome", "Something");
new PropertiesFeatureToggleVersion(properties);
}
@Test
public void testFeatureTurnedOn() throws Exception {
final Properties properties = new Properties();
properties.put("enhancedWelcome", true);
Service service = new PropertiesFeatureToggleVersion(properties);
assertTrue(service.isEnhanced());
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
assertEquals("Welcome Jamie No Code. You're using the enhanced welcome message.", welcomeMessage);
}
@Test
public void testFeatureTurnedOff() throws Exception {
final Properties properties = new Properties();
properties.put("enhancedWelcome", false);
Service service = new PropertiesFeatureToggleVersion(properties);
assertFalse(service.isEnhanced());
final String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
assertEquals("Welcome to the application.", welcomeMessage);
}
}

View File

@ -0,0 +1,64 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.pattern.tieredversion;
import com.iluwatar.featuretoggle.pattern.Service;
import com.iluwatar.featuretoggle.user.User;
import com.iluwatar.featuretoggle.user.UserGroup;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TieredFeatureToggleVersionTest {
final User paidUser = new User("Jamie Coder");
final User freeUser = new User("Alan Defect");
final Service service = new TieredFeatureToggleVersion();
@Before
public void setUp() throws Exception {
UserGroup.addUserToPaidGroup(paidUser);
UserGroup.addUserToFreeGroup(freeUser);
}
@Test
public void testGetWelcomeMessageForPaidUser() throws Exception {
final String welcomeMessage = service.getWelcomeMessage(paidUser);
final String expected = "You're amazing Jamie Coder. Thanks for paying for this awesome software.";
assertEquals(expected, welcomeMessage);
}
@Test
public void testGetWelcomeMessageForFreeUser() throws Exception {
final String welcomeMessage = service.getWelcomeMessage(freeUser);
final String expected = "I suppose you can use this software.";
assertEquals(expected, welcomeMessage);
}
@Test
public void testIsEnhancedAlwaysTrueAsTiered() throws Exception {
assertTrue(service.isEnhanced());
}
}

View File

@ -0,0 +1,59 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.featuretoggle.user;
import org.junit.Test;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;
public class UserGroupTest {
@Test
public void testAddUserToFreeGroup() throws Exception {
User user = new User("Free User");
UserGroup.addUserToFreeGroup(user);
assertFalse(UserGroup.isPaid(user));
}
@Test
public void testAddUserToPaidGroup() throws Exception {
User user = new User("Paid User");
UserGroup.addUserToPaidGroup(user);
assertTrue(UserGroup.isPaid(user));
}
@Test(expected = IllegalArgumentException.class)
public void testAddUserToPaidWhenOnFree() throws Exception {
User user = new User("Paid User");
UserGroup.addUserToFreeGroup(user);
UserGroup.addUserToPaidGroup(user);
}
@Test(expected = IllegalArgumentException.class)
public void testAddUserToFreeWhenOnPaid() throws Exception {
User user = new User("Free User");
UserGroup.addUserToPaidGroup(user);
UserGroup.addUserToFreeGroup(user);
}
}

View File

@ -29,7 +29,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>flux</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>flyweight</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>front-controller</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>half-sync-half-async</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>intercepting-filter</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>interpreter</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>iterator</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<groupId>com.iluwatar.layers</groupId>
<artifactId>layers</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>lazy-loading</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>mediator</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>memento</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>message-channel</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>model-view-controller</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>model-view-presenter</artifactId>
<name>model-view-presenter</name>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>monostate</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>multiton</artifactId>
<dependencies>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-dom</artifactId>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-fixture</artifactId>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-integtests</artifactId>

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects</artifactId>
@ -350,17 +350,17 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>naked-objects-dom</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>naked-objects-fixture</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>naked-objects-webapp</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -16,7 +16,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-webapp</artifactId>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>null-object</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>object-pool</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>observer</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>poison-pill</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
<packaging>pom</packaging>
<inceptionYear>2014</inceptionYear>
@ -120,6 +120,7 @@
<module>delegation</module>
<module>event-driven-architecture</module>
<module>value-object</module>
<module>feature-toggle</module>
</modules>
<dependencyManagement>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>private-class-data</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>producer-consumer</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>property</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>prototype</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>proxy</artifactId>
<dependencies>

View File

@ -18,6 +18,8 @@ Broadcast messages from sender to all the interested receivers.
## Applicability
Use the Publish Subscribe Channel pattern when
* two or more applications need to communicate using a messaging system for broadcasts.
=======
* two or more applications need to communicate using a messaging system for broadcasts.
##Credits

View File

@ -28,7 +28,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>publish-subscribe</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>reactor</artifactId>
<dependencies>

View File

@ -23,13 +23,14 @@
THE SOFTWARE.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>reader-writer-lock</artifactId>
<dependencies>

View File

@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.reader.writer.lock;
import java.util.concurrent.ExecutorService;

View File

@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.reader.writer.lock;
import static org.mockito.Mockito.inOrder;

View File

@ -20,6 +20,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.reader.writer.lock;
import org.junit.After;

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>repository</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>resource-acquisition-is-initialization</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>servant</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>service-layer</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>service-locator</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>singleton</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>specification</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>state</artifactId>
<dependencies>

View File

@ -30,7 +30,7 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>step-builder</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>strategy</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>template-method</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>thread-pool</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>tolerant-reader</artifactId>
<dependencies>

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>twin</artifactId>
<dependencies>

View File

@ -2,18 +2,21 @@ package com.iluwatar.value.object;
/**
* App Class.
*
*/
public class App {
/**
* main method.
* A Value Object must check equality with equals() not == <br>
* This practice creates three HeroStats(Value object) and checks equality between those.
*/
public static void main(String[] args) {
HeroStat statA = HeroStat.valueOf(10, 5, 0);
HeroStat statB = HeroStat.valueOf(5, 1, 8);
HeroStat statB = HeroStat.valueOf(10, 5, 0);
HeroStat statC = HeroStat.valueOf(5, 1, 8);
System.out.println(statA.toString());
// When using Value Objects do not use ==, only compare using equals().
System.out.println("is statA and statB equal : " + statA.equals(statB));
System.out.println("Is statA and statB equal : " + statA.equals(statB));
System.out.println("Is statA and statC equal : " + statA.equals(statC));
}
}

View File

@ -48,15 +48,15 @@ public class HeroStat {
/*
* Recommended to provide a static factory method capable of creating an instance from the formal
* string representation declared like this. public static Juice parse(String string) {}
* string representation declared like this. public static HeroStat parse(String string) {}
*/
// toString, hashCode, equals
@Override
public String toString() {
return "HeroStat [strength=" + strength + ", intelligence=" + intelligence + ", luck=" + luck
+ "]";
return "HeroStat [strength=" + strength + ", intelligence=" + intelligence
+ ", luck=" + luck + "]";
}
@Override
@ -94,6 +94,6 @@ public class HeroStat {
}
// The clone() method should not be public
// The clone() method should not be public. Just don't override it.
}

View File

@ -0,0 +1,15 @@
package com.iluwatar.value.object;
import org.junit.Test;
/**
* Application test
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
}
}

View File

@ -15,9 +15,10 @@ import org.junit.Test;
public class HeroStatTest {
/**
* Tester for equals() and hashCode() methods of a class.
* Tester for equals() and hashCode() methods of a class. Using guava's EqualsTester
*
* @see http://www.javadoc.io/doc/com.google.guava/guava-testlib/19.0
* @see http://static.javadoc.io/com.google.guava/guava-testlib/19.0/com/google/common/testing/
* EqualsTester.html
*/
@Test
public void testEquals() {

View File

@ -29,7 +29,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.10.0-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
</parent>
<artifactId>visitor</artifactId>
<dependencies>