Giter Club home page Giter Club logo

luxor's Introduction

Luxor

Description

Luxor helps and facilitates the creation of factory, leaving the work focused only on business rule.

Simple example:

Interface
public interface Equipament {

    void process(BigDecimal valor);
}

Impl example:
@FactoryImplRegister(key = "Boot")
public class BootEquipament extends AbstractEquipament {

    @Override
    public void process(BigDecimal value) {
        log.info("Boot impl value: " + value);
    }
}
@FactoryImplRegister(key = "Fone")
public class FoneEquipament implements Equipament {

    public void process(BigDecimal valor) {
        log.info("Process with value: " + valor);
    }
}
  • The annotation @FactoryImplRegister maps the implementation, key will be used to discover the implementation
Discovery example :
Optional<Equipament> foneEquipament = FactoryImplDiscovery.discovery("Fone", Equipament.class);
  
Equipament equipament = foneEquipament.get();

equipament.process(new BigDecimal("100"));

Spring integration

Configure the bean
@Autowired
private ApplicationContext applicationContext;

@Bean
public SpringFactoryImplDiscovery factoryImplDiscovery() {
    return new SpringFactoryImplDiscovery(applicationContext);
}

Spring example

@RestController
@RequestMapping("/calculator")
public class LuxorApi {

    @Autowired
    private SpringFactoryImplDiscovery springFactoryImplDiscovery;

    // Operation (+,-,*)
    @GetMapping("/execute/{operation}")
    public ResponseEntity teste(@PathVariable("operation") String operation) {

        Calculator calculator = springFactoryImplDiscovery.discoveryBeanOrThrow(operation, Calculator.class);

        return ResponseEntity.ok(calculator.execute(100D, 20D));
    }

}

Interface or abstract class
public interface Calculator {
    Double execute(@NonNull Double value1, @NonNull Double value2);
}
Impls example
@FactoryImplRegister(key = "+")
@Service
public class Addition implements Calculator {

    @Override
    public Double execute(Double value1, Double value2) {
        return value1 + value2;
    }
}
@FactoryImplRegister(key = "*")
@Service
public class Multiplication implements Calculator {

    @Override
    public Double execute(Double value1, Double value2) {
        return value1 * value2;
    }
}
@FactoryImplRegister(key = "-")
@Service
public class Subtraction implements Calculator {

    @Override
    public Double execute(Double value1, Double value2) {
        return value1 - value2;
    }
}

Install:
<repositories>
  <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
  </repository>
</repositories>
  
<dependency>
    <groupId>com.github.luxorfactory4j</groupId>
    <artifactId>luxor</artifactId>
    <version>ad289b1eed</version>
</dependency>

luxor's People

Contributors

jeremiassantos avatar joaopbini avatar

Watchers

James Cloos avatar Tiago Soares de Gois avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.