Java language
Java package-private helper and public facade
A public entry point delegates to a package-accessible implementation type without exposing that type to clients. Multi-file example: save each labeled section separately. Compile the listed files with javac --release 21 -d out and run java -cp out demo.app.Main.
Formal Syntax & Structure
java syntaxjava
public class Price { /* public operations */ }Working Example
Example Snippetjava
// File: src/demo/pricing/Price.javapackage demo.pricing;public class Price { public static int total(int quantity) { return Rules.unitPrice() * Rules.checked(quantity); }}
// File: src/demo/pricing/Rules.javapackage demo.pricing;final class Rules { static int unitPrice() { return 6; } static int checked(int quantity) { if (quantity < 0 || quantity > 100) throw new IllegalArgumentException("Quantity out of range"); return quantity; }}
// File: src/demo/app/Main.javapackage demo.app;import demo.pricing.Price;public class Main { public static void main(String[] args) { System.out.println(Price.total(3)); try { Price.total(101); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } }}