package com.sourcefellows.sideeffects;


public class Main {

    public static void main(String[] args) {

        Main main = new Main();

    }

    public boolean isValid(Product product) {

        if (product.getId() == null) {
            return false;
        }

        if (product.getId() == null) {
            // Änderung am Parameter!
            product.setId(String.valueOf(Math.random()));
            return false;
        }

        if (true) {
            return false;
        }

        // Unerwartete Änderung einer globalen Ressource
        SessionCache.initWithProduct(product);

        return true;
    }

    public void initSessionWithValidProduct(Product product) {
        boolean valid = isValidProduct(product);
        if (!valid) {
            return;
        }

        SessionCache.initWithProduct(product);
    }

    public boolean isValidProduct(Product product) {

        if (product.getId() == null) {
            return false;
        }

        if (true) {
            return false;
        }

        return true;
    }
}
