public class App { public static void main(String[] args) { // Выбор реализаций = расширение без изменения кода сервисов (OCP) Payment payment = new CardPayment(); // легко заменить на PaypalPayment Notifier notifier = new EmailNotifier(); // или SmsNotifier DiscountPolicy discount = new TenPercentDiscount(); // или NoDiscount OrderRepository repo = new InMemoryOrderRepository(); PricingService pricing = new PricingService(discount); CheckoutService checkout = new CheckoutService(payment, notifier, repo, pricing); var order = new Order("user@example.com", new Money("RUB", new java.math.BigDecimal("1000.00"))); checkout.checkout(order); } }
public class App { public static void main(String[] args) { // Выбор реализаций = расширение без изменения кода сервисов (OCP) Payment payment = new CardPayment(); // легко заменить на PaypalPayment Notifier notifier = new EmailNotifier(); // или SmsNotifier DiscountPolicy discount = new TenPercentDiscount(); // или NoDiscount OrderRepository repo = new InMemoryOrderRepository(); PricingService pricing = new PricingService(discount); CheckoutService checkout = new CheckoutService(payment, notifier, repo, pricing); var order = new Order("user@example.com", new Money("RUB", new java.math.BigDecimal("1000.00"))); checkout.checkout(order); } }
// Пример кода
function hello(name) {
console.log(`Hi, ${name}!`);
}
hello("Sergey");