Giter Club home page Giter Club logo

sf-java's Introduction

StoreFront

Build Status Coverage Status

Introduction

Example of using Simple Rules to determine item worth and ShelfLife of a project.

  • com.lcamilo.other_team.model.Item Cannot be altered as it is maintained by another team that doesn’t believe in shared code ownership. To solve this, an Item adapter was created com.lcamilo.store_front.model.ItemRuleAdapter which wraps an Item and add functionality without having to alter the other teams code.

  • Two solutions were implemented which both implement an InventoryWorthCalculator:

    A modified implementation of the original code, com.lcamilo.store_front.service.LegacyInventoryWorthCalculator which simplifies the logic by making the code a little more readable.

       public CalculableItem updateWorth(CalculableItem calculableItem) {
        applyGoldRule(calculableItem);
        applyHeliumRule(calculableItem);
        applyCadmiumRule(calculableItem);
        applyAlchemyRule(calculableItem);
        applyMaxWorthValueRule(calculableItem);
        applyMinWorthValueRule(calculableItem);
        applyRegularItemValueRule(calculableItem);
        calculableItem.incrementShelfLifeBy(-1);
        return calculableItem;
      }
    

    A dynamic rule worth based calculator, [com.lcamilo.store_front.service.RuleBasedInventoryWorthCalculator] (https://github.com/lcamilo15/sf-java/blob/master/src/main/java/com/lcamilo/store_front/service/RuleBasedInventoryWorthCalculator.java). A more flexible approach using a simple Rules engine by creating a modified version of a command pattern.

     itemRules = ItemRuleBuilder.newBuilder()
        .addRule(
            when(IS_REGULAR_ITEM.and(SHELF_DATE_HAS_NOT_PASSED)),
            then(incrementBy(incrementValueBy, defaultMaxWorthValue))
        )

sf-java's People

Watchers

 avatar  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.