mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 07:25:41 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -33,8 +33,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* application, like the abstract factory pattern, does. - avoid the inherent cost of creating a new
|
||||
* object in the standard way (e.g., using the 'new' keyword)
|
||||
*
|
||||
* <p>In this example we have a factory class ({@link HeroFactoryImpl}) producing objects by
|
||||
* cloning the existing ones. The factory's prototype objects are given as constructor parameters.
|
||||
* <p>In this example we have a factory class ({@link HeroFactoryImpl}) producing objects by cloning
|
||||
* the existing ones. The factory's prototype objects are given as constructor parameters.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
@@ -45,11 +45,9 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
var factory = new HeroFactoryImpl(
|
||||
new ElfMage("cooking"),
|
||||
new ElfWarlord("cleaning"),
|
||||
new ElfBeast("protecting")
|
||||
);
|
||||
var factory =
|
||||
new HeroFactoryImpl(
|
||||
new ElfMage("cooking"), new ElfWarlord("cleaning"), new ElfBeast("protecting"));
|
||||
var mage = factory.createMage();
|
||||
var warlord = factory.createWarlord();
|
||||
var beast = factory.createBeast();
|
||||
@@ -57,11 +55,8 @@ public class App {
|
||||
LOGGER.info(warlord.toString());
|
||||
LOGGER.info(beast.toString());
|
||||
|
||||
factory = new HeroFactoryImpl(
|
||||
new OrcMage("axe"),
|
||||
new OrcWarlord("sword"),
|
||||
new OrcBeast("laser")
|
||||
);
|
||||
factory =
|
||||
new HeroFactoryImpl(new OrcMage("axe"), new OrcWarlord("sword"), new OrcBeast("laser"));
|
||||
mage = factory.createMage();
|
||||
warlord = factory.createWarlord();
|
||||
beast = factory.createBeast();
|
||||
|
||||
@@ -27,14 +27,10 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Beast.
|
||||
*/
|
||||
/** Beast. */
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
public abstract class Beast extends Prototype<Beast> {
|
||||
|
||||
public Beast(Beast source) {
|
||||
}
|
||||
|
||||
public Beast(Beast source) {}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* ElfBeast.
|
||||
*/
|
||||
/** ElfBeast. */
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@RequiredArgsConstructor
|
||||
public class ElfBeast extends Beast {
|
||||
@@ -45,5 +43,4 @@ public class ElfBeast extends Beast {
|
||||
public String toString() {
|
||||
return "Elven eagle helps in " + helpType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* ElfMage.
|
||||
*/
|
||||
/** ElfMage. */
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@RequiredArgsConstructor
|
||||
public class ElfMage extends Mage {
|
||||
@@ -45,5 +43,4 @@ public class ElfMage extends Mage {
|
||||
public String toString() {
|
||||
return "Elven mage helps in " + helpType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* ElfWarlord.
|
||||
*/
|
||||
/** ElfWarlord. */
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@RequiredArgsConstructor
|
||||
public class ElfWarlord extends Warlord {
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.
|
||||
*/
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/**
|
||||
* Interface for the factory class.
|
||||
*/
|
||||
public interface HeroFactory {
|
||||
|
||||
Mage createMage();
|
||||
|
||||
Warlord createWarlord();
|
||||
|
||||
Beast createBeast();
|
||||
|
||||
}
|
||||
/*
|
||||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
|
||||
*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2022 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.
|
||||
*/
|
||||
package com.iluwatar.prototype;
|
||||
|
||||
/** Interface for the factory class. */
|
||||
public interface HeroFactory {
|
||||
|
||||
Mage createMage();
|
||||
|
||||
Warlord createWarlord();
|
||||
|
||||
Beast createBeast();
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.prototype;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Concrete factory class.
|
||||
*/
|
||||
/** Concrete factory class. */
|
||||
@RequiredArgsConstructor
|
||||
public class HeroFactoryImpl implements HeroFactory {
|
||||
|
||||
@@ -36,25 +34,18 @@ public class HeroFactoryImpl implements HeroFactory {
|
||||
private final Warlord warlord;
|
||||
private final Beast beast;
|
||||
|
||||
/**
|
||||
* Create mage.
|
||||
*/
|
||||
/** Create mage. */
|
||||
public Mage createMage() {
|
||||
return mage.copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create warlord.
|
||||
*/
|
||||
/** Create warlord. */
|
||||
public Warlord createWarlord() {
|
||||
return warlord.copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create beast.
|
||||
*/
|
||||
/** Create beast. */
|
||||
public Beast createBeast() {
|
||||
return beast.copy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,14 +27,10 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Mage.
|
||||
*/
|
||||
/** Mage. */
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
public abstract class Mage extends Prototype<Mage> {
|
||||
|
||||
public Mage(Mage source) {
|
||||
}
|
||||
|
||||
public Mage(Mage source) {}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* OrcBeast.
|
||||
*/
|
||||
/** OrcBeast. */
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@RequiredArgsConstructor
|
||||
public class OrcBeast extends Beast {
|
||||
@@ -45,5 +43,4 @@ public class OrcBeast extends Beast {
|
||||
public String toString() {
|
||||
return "Orcish wolf attacks with " + weapon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* OrcMage.
|
||||
*/
|
||||
/** OrcMage. */
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@RequiredArgsConstructor
|
||||
public class OrcMage extends Mage {
|
||||
@@ -45,5 +43,4 @@ public class OrcMage extends Mage {
|
||||
public String toString() {
|
||||
return "Orcish mage attacks with " + weapon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* OrcWarlord.
|
||||
*/
|
||||
/** OrcWarlord. */
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@RequiredArgsConstructor
|
||||
public class OrcWarlord extends Warlord {
|
||||
@@ -45,5 +43,4 @@ public class OrcWarlord extends Warlord {
|
||||
public String toString() {
|
||||
return "Orcish warlord attacks with " + weapon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,15 +27,11 @@ package com.iluwatar.prototype;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Prototype.
|
||||
*/
|
||||
/** Prototype. */
|
||||
@Slf4j
|
||||
public abstract class Prototype<T> implements Cloneable {
|
||||
|
||||
/**
|
||||
* Object a shallow copy of this object or null if this object is not Cloneable.
|
||||
*/
|
||||
/** Object a shallow copy of this object or null if this object is not Cloneable. */
|
||||
@SuppressWarnings("unchecked")
|
||||
@SneakyThrows
|
||||
public T copy() {
|
||||
|
||||
@@ -27,14 +27,10 @@ package com.iluwatar.prototype;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Warlord.
|
||||
*/
|
||||
/** Warlord. */
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
public abstract class Warlord extends Prototype<Warlord> {
|
||||
|
||||
public Warlord(Warlord source) {
|
||||
}
|
||||
|
||||
public Warlord(Warlord source) {}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
/** Application test */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,12 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
class PrototypeTest<P extends Prototype<P>> {
|
||||
static Collection<Object[]> dataProvider() {
|
||||
return List.of(
|
||||
new Object[]{new OrcBeast("axe"), "Orcish wolf attacks with axe"},
|
||||
new Object[]{new OrcMage("sword"), "Orcish mage attacks with sword"},
|
||||
new Object[]{new OrcWarlord("laser"), "Orcish warlord attacks with laser"},
|
||||
new Object[]{new ElfBeast("cooking"), "Elven eagle helps in cooking"},
|
||||
new Object[]{new ElfMage("cleaning"), "Elven mage helps in cleaning"},
|
||||
new Object[]{new ElfWarlord("protecting"), "Elven warlord helps in protecting"}
|
||||
);
|
||||
new Object[] {new OrcBeast("axe"), "Orcish wolf attacks with axe"},
|
||||
new Object[] {new OrcMage("sword"), "Orcish mage attacks with sword"},
|
||||
new Object[] {new OrcWarlord("laser"), "Orcish warlord attacks with laser"},
|
||||
new Object[] {new ElfBeast("cooking"), "Elven eagle helps in cooking"},
|
||||
new Object[] {new ElfMage("cleaning"), "Elven mage helps in cleaning"},
|
||||
new Object[] {new ElfWarlord("protecting"), "Elven warlord helps in protecting"});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -62,5 +61,4 @@ class PrototypeTest<P extends Prototype<P>> {
|
||||
assertSame(testedPrototype.getClass(), clone.getClass());
|
||||
assertEquals(clone, testedPrototype);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user