mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-16 12:59:13 +00:00
* fix checkstlye errors - visitor pattern * fix checkstlye errors - strategy pattern * fix checkstlye errors - singleton pattern
This commit is contained in:
committed by
Ilkka Seppälä
parent
1eb1961f1b
commit
3b1a28149b
@@ -28,15 +28,15 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Strategy pattern (also known as the policy pattern) is a software design pattern that enables
|
||||
* an algorithm's behavior to be selected at runtime.
|
||||
* <p>
|
||||
* Before Java 8 the Strategies needed to be separate classes forcing the developer
|
||||
* <p>The Strategy pattern (also known as the policy pattern) is a software design pattern that
|
||||
* enables an algorithm's behavior to be selected at runtime.</p>
|
||||
*
|
||||
* <p>Before Java 8 the Strategies needed to be separate classes forcing the developer
|
||||
* to write lots of boilerplate code. With modern Java it is easy to pass behavior
|
||||
* with method references and lambdas making the code shorter and more readable.
|
||||
* <p>
|
||||
* In this example ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing object
|
||||
* ({@link DragonSlayer}) can alter its behavior by changing its strategy.
|
||||
* with method references and lambdas making the code shorter and more readable.</p>
|
||||
*
|
||||
* <p>In this example ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing
|
||||
* object ({@link DragonSlayer}) can alter its behavior by changing its strategy.</p>
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
@@ -44,7 +44,7 @@ public class App {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* DragonSlayer uses different strategies to slay the dragon.
|
||||
*
|
||||
*/
|
||||
public class DragonSlayer {
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* Strategy interface.
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DragonSlayingStrategy {
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Melee strategy.
|
||||
*
|
||||
*/
|
||||
public class MeleeStrategy implements DragonSlayingStrategy {
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Projectile strategy.
|
||||
*
|
||||
*/
|
||||
public class ProjectileStrategy implements DragonSlayingStrategy {
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Spell strategy.
|
||||
*
|
||||
*/
|
||||
public class SpellStrategy implements DragonSlayingStrategy {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user