mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 13:26:33 +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:
@@ -35,9 +35,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* <p>In the given example {@link WeaponFactory} represents the factory kit, that contains four
|
||||
* {@link Builder}s for creating new objects of the classes implementing {@link Weapon} interface.
|
||||
*
|
||||
* <p>Each of them can be called with {@link WeaponFactory#create(WeaponType)} method, with
|
||||
* an input representing an instance of {@link WeaponType} that needs to be mapped explicitly with
|
||||
* desired class type in the factory instance.
|
||||
* <p>Each of them can be called with {@link WeaponFactory#create(WeaponType)} method, with an input
|
||||
* representing an instance of {@link WeaponType} that needs to be mapped explicitly with desired
|
||||
* class type in the factory instance.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
@@ -48,12 +48,14 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
var factory = WeaponFactory.factory(builder -> {
|
||||
builder.add(WeaponType.SWORD, Sword::new);
|
||||
builder.add(WeaponType.AXE, Axe::new);
|
||||
builder.add(WeaponType.SPEAR, Spear::new);
|
||||
builder.add(WeaponType.BOW, Bow::new);
|
||||
});
|
||||
var factory =
|
||||
WeaponFactory.factory(
|
||||
builder -> {
|
||||
builder.add(WeaponType.SWORD, Sword::new);
|
||||
builder.add(WeaponType.AXE, Axe::new);
|
||||
builder.add(WeaponType.SPEAR, Spear::new);
|
||||
builder.add(WeaponType.BOW, Bow::new);
|
||||
});
|
||||
var list = new ArrayList<Weapon>();
|
||||
list.add(factory.create(WeaponType.AXE));
|
||||
list.add(factory.create(WeaponType.SPEAR));
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.factorykit;
|
||||
|
||||
/**
|
||||
* Class representing Axe.
|
||||
*/
|
||||
/** Class representing Axe. */
|
||||
public class Axe implements Weapon {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.factorykit;
|
||||
|
||||
/**
|
||||
* Class representing Bows.
|
||||
*/
|
||||
/** Class representing Bows. */
|
||||
public class Bow implements Weapon {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.factorykit;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Functional interface that allows adding builder with name to the factory.
|
||||
*/
|
||||
/** Functional interface that allows adding builder with name to the factory. */
|
||||
public interface Builder {
|
||||
void add(WeaponType name, Supplier<Weapon> supplier);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.factorykit;
|
||||
|
||||
/**
|
||||
* Class representing Spear.
|
||||
*/
|
||||
/** Class representing Spear. */
|
||||
public class Spear implements Weapon {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.factorykit;
|
||||
|
||||
/**
|
||||
* Class representing Swords.
|
||||
*/
|
||||
/** Class representing Swords. */
|
||||
public class Sword implements Weapon {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -24,8 +24,5 @@
|
||||
*/
|
||||
package com.iluwatar.factorykit;
|
||||
|
||||
/**
|
||||
* Interface representing weapon.
|
||||
*/
|
||||
public interface Weapon {
|
||||
}
|
||||
/** Interface representing weapon. */
|
||||
public interface Weapon {}
|
||||
|
||||
@@ -29,11 +29,11 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Functional interface, an example of the factory-kit design pattern.
|
||||
* <br>Instance created locally gives an opportunity to strictly define
|
||||
* which objects types the instance of a factory will be able to create.
|
||||
* <br>Factory is a placeholder for {@link Builder}s
|
||||
* with {@link WeaponFactory#create(WeaponType)} method to initialize new objects.
|
||||
* Functional interface, an example of the factory-kit design pattern. <br>
|
||||
* Instance created locally gives an opportunity to strictly define which objects types the instance
|
||||
* of a factory will be able to create. <br>
|
||||
* Factory is a placeholder for {@link Builder}s with {@link WeaponFactory#create(WeaponType)}
|
||||
* method to initialize new objects.
|
||||
*/
|
||||
public interface WeaponFactory {
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.factorykit;
|
||||
|
||||
/**
|
||||
* Enumerates {@link Weapon} types.
|
||||
*/
|
||||
/** Enumerates {@link Weapon} types. */
|
||||
public enum WeaponType {
|
||||
SWORD,
|
||||
AXE,
|
||||
|
||||
Reference in New Issue
Block a user