mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 18:59:10 +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,12 +27,14 @@ package com.iluwatar.context.object;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* In the context object pattern, information and data from underlying protocol-specific classes/systems is decoupled
|
||||
* and stored into a protocol-independent object in an organised format. The pattern ensures the data contained within
|
||||
* the context object can be shared and further structured between different layers of a software system.
|
||||
* In the context object pattern, information and data from underlying protocol-specific
|
||||
* classes/systems is decoupled and stored into a protocol-independent object in an organised
|
||||
* format. The pattern ensures the data contained within the context object can be shared and
|
||||
* further structured between different layers of a software system.
|
||||
*
|
||||
* <p> In this example we show how a context object {@link ServiceContext} can be initiated, edited and passed/retrieved
|
||||
* in different layers of the program ({@link LayerA}, {@link LayerB}, {@link LayerC}) through use of static methods. </p>
|
||||
* <p>In this example we show how a context object {@link ServiceContext} can be initiated, edited
|
||||
* and passed/retrieved in different layers of the program ({@link LayerA}, {@link LayerB}, {@link
|
||||
* LayerC}) through use of static methods.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
@@ -45,19 +47,21 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
//Initiate first layer and add service information into context
|
||||
// Initiate first layer and add service information into context
|
||||
var layerA = new LayerA();
|
||||
layerA.addAccountInfo(SERVICE);
|
||||
|
||||
logContext(layerA.getContext());
|
||||
|
||||
//Initiate second layer and preserving information retrieved in first layer through passing context object
|
||||
// Initiate second layer and preserving information retrieved in first layer through passing
|
||||
// context object
|
||||
var layerB = new LayerB(layerA);
|
||||
layerB.addSessionInfo(SERVICE);
|
||||
|
||||
logContext(layerB.getContext());
|
||||
|
||||
//Initiate third layer and preserving information retrieved in first and second layer through passing context object
|
||||
// Initiate third layer and preserving information retrieved in first and second layer through
|
||||
// passing context object
|
||||
var layerC = new LayerC(layerB);
|
||||
layerC.addSearchInfo(SERVICE);
|
||||
|
||||
@@ -67,4 +71,4 @@ public class App {
|
||||
private static void logContext(ServiceContext context) {
|
||||
LOGGER.info("Context = {}", context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.context.object;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Layer A in the context object pattern.
|
||||
*/
|
||||
/** Layer A in the context object pattern. */
|
||||
@Getter
|
||||
public class LayerA {
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.context.object;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Layer B in the context object pattern.
|
||||
*/
|
||||
/** Layer B in the context object pattern. */
|
||||
@Getter
|
||||
public class LayerB {
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ package com.iluwatar.context.object;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Layer C in the context object pattern.
|
||||
*/
|
||||
/** Layer C in the context object pattern. */
|
||||
@Getter
|
||||
public class LayerC {
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ package com.iluwatar.context.object;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Where context objects are defined.
|
||||
*/
|
||||
/** Where context objects are defined. */
|
||||
@Getter
|
||||
@Setter
|
||||
public class ServiceContext {
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.context.object;
|
||||
|
||||
/**
|
||||
* An interface to create context objects passed through layers.
|
||||
*/
|
||||
/** An interface to create context objects passed through layers. */
|
||||
public class ServiceContextFactory {
|
||||
|
||||
public static ServiceContext createContext() {
|
||||
|
||||
Reference in New Issue
Block a user