Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
Jeżeli ktoś rozróżnia naukę (poznanie) i zabawę, to nie zrozumiał żadnego z tych pojęć.
Alternatywa: Command+CommandHandler w architekturze Command query Responsibility Segregation
@Transactional
@Service
//...
public class OrderService{
..@Autowired
..private OrdersRepository ordersRepository;
..@Autowired
..private PreductsRepository productssRepository;
..public void addProductToOrder(Long orderId, Long productId, int quantity){
....Order order = ordersRepository.load(orderId);
....Product product = productssRepository.load(productId);
....order.addProduct(product, quantity);
....ordersRepository.save(order);
..}
}
@Service
@Transactional
//..
public class OrderService{
..@Autowired
..private OrdersRepository ordersRepository;
..@Autowired
..private InvoicesRepository invoicesRepository;
..public void submitOrder(Long orderId, Payment payment){
....Order order = ordersRepository.get(orderId);
....order.confirm(payment);
....BookKeeperService bookKeeper = new BookKeeperService();//testability!!!
....Invoice invoice = bookKeeper.generateInvoice(order);
....ordersRepository.save(order);
....invoicesRepository.save(invoice)
..}
}
Building Blocks
BigDecimal/int value;
Currency curency;
Timestamp currencyRateDate;
if (p1 == null) ...
if (p1 > 1) ...
//chwileczkę... 80% to 0.8 czy 80?
Probability p1 = Probability.fromPercent(80.0);
...
Probability probability = p1.and(p2);
Double probability = p1 * p2;
public class BookKeeperService{
..private TaxCalulatorPolicy taxCalculator;
..public BookKeeperService(...){
....//ew. wstrzyknięcie
..}
..public Invoice generateInvoice(Order order){
....//metoda, która nie pasuje do żadnego Agregatu
....//nie jest esencją istnienia Zamówienia
..}
}
@Entity
public class Order extends AggregateRoot{
..public void confirm(Payment payment){
....if (status == CONFIRMED)
......throw new InvalidStateException();
....status = CONFIRMED;
....createDate = new Date();
....fireEvent(orderEventsFactory.orderSubmitted(getId()));
..}
}
@Entity
public class Order extends AggregateRoot{
..@OneToMany
..private List<OrderItem> items;
..@Embeded
..private Money sum;
..private RebatePolicy rebatePolicy;
..//status, createDate, rebatePolicy
..public Order(RebatePolicy rebatePolicy){
....this.rebatePolicy = rebatePolicy;
....sum = new Money(0.0);
....//...
}
..public void add(Product p, int quantity){
....OrderItem oi = orderItemFactory.build(p, quantity, rebatePolicy);
....items.add(oi);
....sum = sum.add(oi.getCost());
}
..//zwracamy niemodyfikowalną listę Value Objects aby ukryć impl
..public List<OrderedProduct> getOrderItems(){
....return repack(items);
..}
}
"Make explicit what is implicit"
"Make explicit what is implicit"
"Make explicit what is implicit"
public interface RebatePolicy{
..public Money calculateRebate(...);
}
public class OrderItem{
..RebatePolicy rebatePolicy;
..public Money calculateCost(){
//logika biznesowa
Money rebate = rebatePolicy.calculateRebate(...);
//nieco więcej logiki
..}
}
VipRebate
WinterRebate
"Make explicit what is implicit"
Można zastanowić się nad tym, które z DODATKOWYCH obliczeń muszą być wykonane natychmiast...
Integracja z innymi Bounded Context
public class OrderTrackingSaga extends Saga<OrderTrackingSagaData>{
..@SagaAction
..public void handle(CustomerBilledForOrder event)
....memento.setCustomerHasBeenBilled(true);
....memento.setCustomerId(event.getCustomerId());
....memento.setOrderId(event.getOrderId());
....completeIfPossible();
..}
..@SagaAction
..public void handle(OrderSubmitted event){
....memento.setProductIdsInOrder = event.ProductIdsInOrder;
....memento.setCustomerId(event.getCustomerId());
....memento.setOrderId(event.getOrderId());
....completeIfPossible();
}
..private void completeIfPossible(){
....//if (...)
....//fire event, call cervice/send command
....markAsCompleted();
..}
public class Client extends AggregateRoot {
....public void changeStatus(ClientStatus status){
........this.status = status;
........//wiecej logiki biznesowej
........if (status == VIP){
............//rabat na niezrealizowane zamówienia
........}
....}
}
"Make explicit what is implicit"
nieustanne zbieranie wiedzy
wspólne rozumienie
Nowy
język
SOA
Nowa
specyfiakcja
platformy,
servera
"What Drives our Design?"
XML
Kolejny framework webowy
W projekcie brakuje czasu/pieniędzy na rzetelne modelowanie...
Procesy ewolucyjne są ślepe. Czasem osiągają lokalne maksimum, z którego nie mogą się już wydostać.
Richard Dawkins
algorytmiczna