Software architecture

Inventory reservation boundary

Keep check and update inside inventory. Executed Java 21 fixture.

Formal Syntax & Structure

java syntaxjava
Stock.reserve(n)

Working Example

Example Snippetjava
public class Main {    static class Stock {        private int count;        Stock(int count) { if (count < 0) throw new IllegalArgumentException(); this.count=count; }        synchronized boolean reserve(int n) {            if (n <= 0) throw new IllegalArgumentException("quantity");            if (n > count) return false;            count -= n; return true;        }        synchronized int left() { return count; }    }    static String place(Stock stock,int n) { return stock.reserve(n) ? "ACCEPTED" : "REJECTED"; }    public static void main(String[] args) {        var stock = new Stock(3);        System.out.println(place(stock,2));        System.out.println(place(stock,2));        System.out.println(stock.left());    }}
Java Reference