Wzorce projektowe at JInkubator

44

Transcript of Wzorce projektowe at JInkubator

Page 1: Wzorce projektowe at JInkubator
Page 2: Wzorce projektowe at JInkubator

developer,

agile coach

@Pragmatists

właściciel

agile-elearning.pl

Krzysztof Jelski

[email protected] @krzysztofjelski

Page 3: Wzorce projektowe at JInkubator

• przykład

• historia

• przegląd

• jdk

• zasoby

Wzorce projektowe

Page 4: Wzorce projektowe at JInkubator

Feature: Basic sales

Scenario: Standard order includes shipping cost

Given client wants to buy items:

| price | type |

| 100 | cd |

| 100 | book |

When client views the order summary

Then total of the order is 215

Scenario: Order of books only has lower shipping cost

Given client wants to buy items:

| price | type |

| 50 | book |

| 50 | book |

When client views the order summary

Then total of the order is 105

Page 5: Wzorce projektowe at JInkubator

Scenario: Order of books only worth more than 200 is free

Given client wants to buy items:

| price | type |

| 100 | book |

| 105 | book |

When client views the order summary

Then total of the order is 205

Scenario: International shipping of light items

Given client wants to buy items:

| price | weight |

| 100 | 1 |

And wants them delivered to 'Germany'

When client views the order summary

Then total of the order is 150

Scenario: International shipping of heavy items

Given client wants to buy items:

| price | weight |

| 100 | 15 |

And wants them delivered to 'Germany'

When client views the order summary

Then total of the order is 170

Page 6: Wzorce projektowe at JInkubator

KOD

Page 7: Wzorce projektowe at JInkubator
Page 8: Wzorce projektowe at JInkubator

2 najlepsze zasady

projektowania obiektowego

1. Preferuj kompozycję nad dziedziczenie

2. Znajdź to co się zmienia i hermetyzuj to

Page 9: Wzorce projektowe at JInkubator

Algorytm wyliczania całkowitego

kosztu zamówienia

● Oblicz koszt pozycji

● Oblicz koszt wysyłki

● Zsumuj

Page 10: Wzorce projektowe at JInkubator

Standard Promocja na

książki Zagranica

Koszt

wysyłki stała stawka

za darmo jeśli

> 200,

5 jeśli nie

stawka

międzynarodowa,

wyższa gdy

zamówienie jest

ciężkie

Page 11: Wzorce projektowe at JInkubator

SalesOrder

+getTotal()

LineItems

Page 12: Wzorce projektowe at JInkubator

SalesOrder

+getTotal()

StandardSalesOrder

+getTotal()

BooksSalesOrder

+getTotal()

InternationalSalesOrder

+getTotal()

Page 13: Wzorce projektowe at JInkubator

SalesOrder

+getTotal()

#shippingCost()

StandardSalesOrder

#shippingCost()

BooksSalesOrder

#shippingCost()

InternationalSalesOrder

#shippingCost()

Page 14: Wzorce projektowe at JInkubator

SalesOrder

+getTotal()

StandardShippingCost

#shippingCost()

BooksShippingCost

#shippingCost()

InternationalShippingCost

#shippingCost()

ShippingCost

+shippingCost(salesOrder)

Page 15: Wzorce projektowe at JInkubator

SalesOrder

+getTotal()

StandardShippingCost

#shippingCost()

BooksShippingCost

#shippingCost()

InternationalShippingCost

#shippingCost()

ShippingCost

+shippingCost(salesOrder)

Page 16: Wzorce projektowe at JInkubator

Strategy

algorithmInterface()

ConcreteStrategyB

algorithmInterface()

ConcreteStrategyA

algorithmInterface()

strategy Context

contextInterface()

Page 17: Wzorce projektowe at JInkubator

Behawioralne

Strukturalne

Konstrukcyjne

Page 18: Wzorce projektowe at JInkubator

• definiuje rodzinę wymiennych

algorytmów

• hermetyzuje je w postaci klas

• umożliwia wymianę algorytmów

niezależnie od klienta kontekstu

Page 19: Wzorce projektowe at JInkubator

• Możliwość zmiany zachowania

Kontekstu przez zmianę Strategii

• Mniej if-ów

• Klient musi znać różnice między

strategiami by wybrać właściwą

Page 20: Wzorce projektowe at JInkubator
Page 21: Wzorce projektowe at JInkubator
Page 22: Wzorce projektowe at JInkubator

"Each pattern is a three-part rule, which

expresses a relation between a certain

context, a problem, and a solution."

-Christopher Alexander

Page 23: Wzorce projektowe at JInkubator
Page 24: Wzorce projektowe at JInkubator

23

Page 25: Wzorce projektowe at JInkubator

• nazwa

• problem

• rozwiązanie

• konsekwencje

Page 26: Wzorce projektowe at JInkubator

• nazwa

• intencja

• motywacja

• stosowalność

• struktura

• uczestnicy

• współpraca

• konsekwencje

• implementacja

• kod

• zastosowania

• powiązane

wzorce

Page 27: Wzorce projektowe at JInkubator

Silne Luźne

Page 28: Wzorce projektowe at JInkubator

Niska Wysoka

Page 29: Wzorce projektowe at JInkubator

SalesOrder

+getTotal()

StandardShippingCost

#shippingCost()

BooksShippingCost

#shippingCost()

InternationalShippingCost

#shippingCost()

ShippingCost

+shippingCost(salesOrder)

Page 30: Wzorce projektowe at JInkubator
Page 31: Wzorce projektowe at JInkubator
Page 32: Wzorce projektowe at JInkubator
Page 33: Wzorce projektowe at JInkubator
Page 34: Wzorce projektowe at JInkubator
Page 35: Wzorce projektowe at JInkubator

• rozwiązania powracających

problemów

• nazwy ułatwiają komunikację

• luźne powiązania, wysoka spójność

Page 36: Wzorce projektowe at JInkubator
Page 37: Wzorce projektowe at JInkubator
Page 38: Wzorce projektowe at JInkubator
Page 40: Wzorce projektowe at JInkubator
Page 41: Wzorce projektowe at JInkubator
Page 42: Wzorce projektowe at JInkubator
Page 43: Wzorce projektowe at JInkubator
Page 44: Wzorce projektowe at JInkubator