mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-06-01 18:13:13 +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:
@@ -27,20 +27,17 @@ package com.iluwatar.factory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Factory is an object for creating other objects. It provides a static method to
|
||||
* create and return objects of varying classes, in order to hide the implementation logic
|
||||
* and makes client code focus on usage rather than objects initialization and management.
|
||||
* Factory is an object for creating other objects. It provides a static method to create and return
|
||||
* objects of varying classes, in order to hide the implementation logic and makes client code focus
|
||||
* on usage rather than objects initialization and management.
|
||||
*
|
||||
* <p>In this example an alchemist manufactures coins. CoinFactory is the factory class, and it
|
||||
* provides a static method to create different types of coins.
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program main entry point.
|
||||
*/
|
||||
/** Program main entry point. */
|
||||
public static void main(String[] args) {
|
||||
LOGGER.info("The alchemist begins his work.");
|
||||
var coin1 = CoinFactory.getCoin(CoinType.COPPER);
|
||||
|
||||
@@ -24,11 +24,8 @@
|
||||
*/
|
||||
package com.iluwatar.factory;
|
||||
|
||||
/**
|
||||
* Coin interface.
|
||||
*/
|
||||
/** Coin interface. */
|
||||
public interface Coin {
|
||||
|
||||
String getDescription();
|
||||
|
||||
}
|
||||
|
||||
@@ -24,14 +24,10 @@
|
||||
*/
|
||||
package com.iluwatar.factory;
|
||||
|
||||
/**
|
||||
* Factory of coins.
|
||||
*/
|
||||
/** Factory of coins. */
|
||||
public class CoinFactory {
|
||||
|
||||
/**
|
||||
* Factory method takes as a parameter the coin type and calls the appropriate class.
|
||||
*/
|
||||
/** Factory method takes as a parameter the coin type and calls the appropriate class. */
|
||||
public static Coin getCoin(CoinType type) {
|
||||
return type.getConstructor().get();
|
||||
}
|
||||
|
||||
@@ -28,13 +28,10 @@ import java.util.function.Supplier;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Enumeration for different types of coins.
|
||||
*/
|
||||
/** Enumeration for different types of coins. */
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum CoinType {
|
||||
|
||||
COPPER(CopperCoin::new),
|
||||
GOLD(GoldCoin::new);
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.factory;
|
||||
|
||||
/**
|
||||
* CopperCoin implementation.
|
||||
*/
|
||||
/** CopperCoin implementation. */
|
||||
public class CopperCoin implements Coin {
|
||||
|
||||
static final String DESCRIPTION = "This is a copper coin.";
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.factory;
|
||||
|
||||
/**
|
||||
* GoldCoin implementation.
|
||||
*/
|
||||
/** GoldCoin implementation. */
|
||||
public class GoldCoin implements Coin {
|
||||
|
||||
static final String DESCRIPTION = "This is a gold coin.";
|
||||
|
||||
@@ -32,7 +32,6 @@ class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteWithoutExceptions() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user