mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 08:59:12 +00:00
📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@@ -23,11 +23,10 @@
|
||||
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* <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>
|
||||
*
|
||||
@@ -37,12 +36,11 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* <p>In this example ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing
|
||||
* object ({@link DragonSlayer}) can alter its behavior by changing its strategy.</p>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
|
||||
@@ -23,13 +23,11 @@
|
||||
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class LambdaStrategy {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LambdaStrategy.class);
|
||||
|
||||
public enum Strategy implements DragonSlayingStrategy {
|
||||
MeleeStrategy(() -> LOGGER.info(
|
||||
"With your Excalibur you severe the dragon's head!")),
|
||||
|
||||
@@ -23,16 +23,14 @@
|
||||
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Melee strategy.
|
||||
*/
|
||||
@Slf4j
|
||||
public class MeleeStrategy implements DragonSlayingStrategy {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MeleeStrategy.class);
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
LOGGER.info("With your Excalibur you sever the dragon's head!");
|
||||
|
||||
@@ -23,16 +23,14 @@
|
||||
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Projectile strategy.
|
||||
*/
|
||||
@Slf4j
|
||||
public class ProjectileStrategy implements DragonSlayingStrategy {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectileStrategy.class);
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
LOGGER.info("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
|
||||
|
||||
@@ -23,16 +23,14 @@
|
||||
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Spell strategy.
|
||||
*/
|
||||
@Slf4j
|
||||
public class SpellStrategy implements DragonSlayingStrategy {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SpellStrategy.class);
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
LOGGER.info("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");
|
||||
|
||||
Reference in New Issue
Block a user