2) Модели (SRP)

2) Модели (SRP)


import java.util.UUID; public record Money(String currency, java.math.BigDecimal amount) { public Money add(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.add(other.amount)); } public Money subtract(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.subtract(other.amount)); } } public final class Order { private final String id = UUID.randomUUID().toString(); private final String customerEmail; private Money total; private boolean paid; public Order(String customerEmail, Money total) { this.customerEmail = customerEmail; this.total = total; } public String id() { return id; } public String customerEmail() { return customerEmail; } public Money total() { return total; } public boolean isPaid() { return paid; } public void markPaid() { this.paid = true; } public void applyDiscount(Money discounted) { this.total = discounted; } } public record PaymentResult(boolean success, String txId, String message) { }

Автор: к.п.н., Румянцев Сергей Александрович, доцент Финансового университета при Правительстве РФ; доцент ОЧУВО Международного инновационного университета; Консалтинг, управление разработкой ПО; системный и бизнес анализ; менеджмент; аналитиз данных; управление ИТ. Телефон для связи +79269444818 (мессенджеры)   Короткая ссылка:

2) Модели (SRP)


import java.util.UUID; public record Money(String currency, java.math.BigDecimal amount) { public Money add(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.add(other.amount)); } public Money subtract(Money other) { if (!currency.equals(other.currency)) throw new IllegalArgumentException("Currency mismatch"); return new Money(currency, amount.subtract(other.amount)); } } public final class Order { private final String id = UUID.randomUUID().toString(); private final String customerEmail; private Money total; private boolean paid; public Order(String customerEmail, Money total) { this.customerEmail = customerEmail; this.total = total; } public String id() { return id; } public String customerEmail() { return customerEmail; } public Money total() { return total; } public boolean isPaid() { return paid; } public void markPaid() { this.paid = true; } public void applyDiscount(Money discounted) { this.total = discounted; } } public record PaymentResult(boolean success, String txId, String message) { }

https://webprogr.ru/~02y1O
Короткая ссылка на новость:https://webprogr.ru/~02y1O


// Пример кода
function hello(name) {
  console.log(`Hi, ${name}!`);
}
hello("Sergey");

Последние новости

Рейтинг@Mail.ru