1
JavaAdvanced#design-patterns#oop
Adapter converts one interface into another that a client expects, bridging incompatible interfaces. Decorator wraps an object to add new behavior dynamically without altering its interface or subclassing.
// Adapter: makes LegacyPrinter usable as Printer
class PrinterAdapter implements Printer { LegacyPrinter lp; public void print(String s) { lp.oldPrint(s); } }
// Decorator: adds behavior
InputStream in = new BufferedInputStream(new FileInputStream("f.txt"));