A demonstration of Fluent interfaces / TDD / Functional idioms applied with OOPS
This application handle modes of billing in a veterinary hospital that can be done in three ways:
Single Owner
- One person pays all the bill
Multiple Owners
- Bill distibuted evenly
- One Pays it all
- Each Owner is responsible for some services and pays for the same
Billing Mappings (Cost of services for various animals) are declared in class com.veterinary.Animal
Meta Data
private static final Owner BOB = new Owner("BOB"); private static final Owner JOHN = new Owner("JOHN");
Single Owner
Patient patient = new Patient(Animal.CAT, "Kessels"); patient.perform(Procedure.REGULAR_CHECKUP); SingleOwnerBill decoratedBill = new SingleOwnerBill(patient.bill(), BOB); System.out.println(decoratedBill);
Multiple Owner - Bill Distributed Evenly
Patient patient = new Patient(Animal.HORSE, "Blacky"); patient.perform(Procedure.REGULAR_CHECKUP); patient.perform(Procedure.SURGERY); MultipleOwnerBill decoratedBill = new DistributeEvenlyBill(patient.bill(), BOB, JOHN); System.out.println(decoratedBill.costOccurredFor(BOB)); System.out.println(decoratedBill.costOccurredFor(JOHN)); System.out.println(decoratedBill);
Multiple Owner - One owner pays it all
Patient patient = new Patient(Animal.HORSE, "Blacky"); patient.perform(Procedure.REGULAR_CHECKUP); patient.perform(Procedure.SURGERY); MultipleOwnerBill decoratedBill = new OneOwnerPaysItAll(patient.bill(), BOB, BOB, JOHN); System.out.println(decoratedBill.costOccurredFor(BOB)); System.out.println(decoratedBill.costOccurredFor(JOHN)); System.out.println(decoratedBill);
Multiple Owner - Every owner is responsible for some line items (Procedures/Medicines)
Patient patient = new Patient(Animal.HORSE, "Whitey"); patient.perform(Procedure.REGULAR_CHECKUP); patient.perform(Medicine.PARACETAMOL); patient.perform(Procedure.SURGERY); MultipleOwnerBill decoratedBill = new LineItemsBill(patient.bill(), newLineItem(BOB, Procedure.SURGERY, Medicine.PARACETAMOL), newLineItem(JOHN, Procedure.REGULAR_CHECKUP)); System.out.println(decoratedBill.costOccurredFor(BOB)); System.out.println(decoratedBill.costOccurredFor(JOHN)); System.out.println(decoratedBill);