wzorce projektowe at jinkubator

Post on 16-Jul-2015

79 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

developer,

agile coach

@Pragmatists

właściciel

agile-elearning.pl

Krzysztof Jelski

krzysztof.jelski@pragmatists.pl @krzysztofjelski

• przykład

• historia

• przegląd

• jdk

• zasoby

Wzorce projektowe

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

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

KOD

2 najlepsze zasady

projektowania obiektowego

1. Preferuj kompozycję nad dziedziczenie

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

Algorytm wyliczania całkowitego

kosztu zamówienia

● Oblicz koszt pozycji

● Oblicz koszt wysyłki

● Zsumuj

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

SalesOrder

+getTotal()

LineItems

SalesOrder

+getTotal()

StandardSalesOrder

+getTotal()

BooksSalesOrder

+getTotal()

InternationalSalesOrder

+getTotal()

SalesOrder

+getTotal()

#shippingCost()

StandardSalesOrder

#shippingCost()

BooksSalesOrder

#shippingCost()

InternationalSalesOrder

#shippingCost()

SalesOrder

+getTotal()

StandardShippingCost

#shippingCost()

BooksShippingCost

#shippingCost()

InternationalShippingCost

#shippingCost()

ShippingCost

+shippingCost(salesOrder)

SalesOrder

+getTotal()

StandardShippingCost

#shippingCost()

BooksShippingCost

#shippingCost()

InternationalShippingCost

#shippingCost()

ShippingCost

+shippingCost(salesOrder)

Strategy

algorithmInterface()

ConcreteStrategyB

algorithmInterface()

ConcreteStrategyA

algorithmInterface()

strategy Context

contextInterface()

Behawioralne

Strukturalne

Konstrukcyjne

• definiuje rodzinę wymiennych

algorytmów

• hermetyzuje je w postaci klas

• umożliwia wymianę algorytmów

niezależnie od klienta kontekstu

• Możliwość zmiany zachowania

Kontekstu przez zmianę Strategii

• Mniej if-ów

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

strategiami by wybrać właściwą

"Each pattern is a three-part rule, which

expresses a relation between a certain

context, a problem, and a solution."

-Christopher Alexander

23

• nazwa

• problem

• rozwiązanie

• konsekwencje

• nazwa

• intencja

• motywacja

• stosowalność

• struktura

• uczestnicy

• współpraca

• konsekwencje

• implementacja

• kod

• zastosowania

• powiązane

wzorce

Silne Luźne

Niska Wysoka

SalesOrder

+getTotal()

StandardShippingCost

#shippingCost()

BooksShippingCost

#shippingCost()

InternationalShippingCost

#shippingCost()

ShippingCost

+shippingCost(salesOrder)

• rozwiązania powracających

problemów

• nazwy ułatwiają komunikację

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

top related