Skip to content

Latest commit

 

History

History

single-chain-example

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Single Chain Example

This is the most simple and straightforward COR Bean Processor Spring Boot Starter example. It contains a chain or responsibility to find out which type is an object: double, integer, null or string.

An Unified Modeling (UML) Diagram presenting the structure developed to create the type finder chain links.

Highlights

TypeFinderLink interface extends COR Bean Processor Spring Boot Starter ChainLink<T> interface passing a self-reference as parameter. It also contains the entry method used to find an object type.

public interface TypeFinderLink extends ChainLink<TypeFinderLink> {

    String findType(Object object);
}

AbstractTypeFinderLink, as the name says, is an abstract class that implements TypeFinderLink interface. It also implements findType demanded by TypeFinderLink and setNext demanded by ChainLink. The latter is implemented using Lombok @Setter annotation.

public abstract class AbstractTypeFinderLink implements TypeFinderLink {

    @Setter
    private TypeFinderLink next;

    @Override
    public String findType(Object object) { /* Full logic can be checked in the code implementation. */ }
}

TypeFinder encapsulates the components required to find an object type. It contains a findType method which invokes the first link findType method, starting the chain analysis.

public class TypeFinder {

    private final TypeFinderLink firstLink;

    public String findType(Object object) {
        return firstLink.findType(object);
    }
}

COR Bean Processor Spring Boot Starter will be responsible to chain all TypeFinderLink implementations and inject the first chain link on firstLink field.

Execution

The complete integration with Spring Boot can be checked on SingleChainExampleIT class. It is an integration test and can be executed through an IDE like IntelliJ IDEA, Eclipse or Visual Studio Code.

Alternatively, the test can also be executed through a terminal using the following command.

mvn test-compile failsafe:integration-test