Add all 23 GoF design pattern implementations

This commit is contained in:
2026-07-25 10:50:29 +05:30
commit f5688a6b32
164 changed files with 4371 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package adapter;
public class Main {
public static void main(String[] args) {
System.out.println("=== Adapter Design Pattern Demo ===\n");
// --- Object Adapter: Stripe ---
System.out.println("-- Using Stripe via Adapter --");
StripeClient stripeClient = new StripeClient("sk_test_4eC39HqLyjWDarjtT1zdp7dc");
PaymentGateway stripeGateway = new StripePaymentAdapter(stripeClient);
OrderService orderService = new OrderService(stripeGateway);
orderService.processOrder("ORD-001", "cus_abc123", 99.99);
System.out.println("\n-- Testing refund --");
boolean refunded = stripeGateway.refund("ch_ORD-001", 99.99);
System.out.println("Refund issued: " + refunded);
// --- JDK Example: InputStreamReader as Adapter ---
System.out.println("\n-- JDK Adapter: InputStreamReader --");
System.out.println("InputStreamReader wraps System.in (InputStream) as a Reader.");
System.out.println("Your code reads chars; the adapter handles byte-to-char conversion.");
System.out.println("\n=== Demo complete ===");
}
}