OReilly.Head.First.Design.Patterns.2004.pdf

(40256 KB) Pobierz
784104659.041.png
Chapter 1. Welcome to Design Patterns
Table of Contents
Chapter 1. Welcome to Design Patterns. ...................................................... 1
Section 1.1. It started with a simple SimUDuck app ....................................................................................................................... 2
Section 1.2. But now we need the ducks to FLY ............................................................................................................................. 3
Section 1.3. But something went horribly wrong.... ....................................................................................................................... 4
Section 1.4. Joe thinks about inheritance... .................................................................................................................................... 5
Section 1.5. Sharpen your pencil ..................................................................................................................................................... 5
Section 1.6. How about an interface? ............................................................................................................................................. 6
Section 1.7. What would you do if you were Joe? ........................................................................................................................... 7
Section 1.8. The one constant in software development ................................................................................................................ 8
Section 1.9. Sharpen your pencil .................................................................................................................................................... 8
Section 1.10. Zeroing in on the problem... ...................................................................................................................................... 9
Section 1.11. Separating what changes from what stays the same ............................................................................................... 10
Section 1.12. Designing the Duck Behaviors .................................................................................................................................. 11
Section 1.13. Implementing the Duck Behaviors .......................................................................................................................... 13
Section 1.14. There are no Dumb Questions ................................................................................................................................. 14
Section 1.15. Sharpen your pencil .................................................................................................................................................. 14
Section 1.16. Integrating the Duck Behavior ................................................................................................................................. 15
Section 1.17. More Integration... ................................................................................................................................................... 16
Section 1.18. Testing the Duck code .............................................................................................................................................. 18
Section 1.19. Setting behavior dynamically. ................................................................................................................................. 20
Section 1.20. The Big Picture on encapsulated behaviors ............................................................................................................ 22
Section 1.21. HAS-A can be better than IS-A ................................................................................................................................ 23
Section 1.22. Speaking of Design Patterns... ................................................................................................................................ 24
Section 1.23. Design Puzzle ........................................................................................................................................................... 25
Section 1.24. Overheard at the local diner... ................................................................................................................................. 26
Section 1.25. Overheard in the next cubicle... ............................................................................................................................... 27
Section 1.26. The power of a shared pattern vocabulary ............................................................................................................. 28
Section 1.27. How do I use Design Patterns? ............................................................................................................................... 29
Section 1.28. There are no Dumb Questions. ............................................................................................................................... 29
Section 1.29. Skeptical Developer-Friendly Patterns Guru ......................................................................................................... 30
Section 1.30. Tools for your Design Toolbox ................................................................................................................................ 32
Section 1.31. Design Puzzle Solution ............................................................................................................................................ 34
Section 1.32. Solutions .................................................................................................................................................................. 35
Chapter 1. Welcome to Design Patterns
Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra
ISBN: 0596007124 Publisher: O'Reilly
Prepared for Ann Cherkis, Safari ID: maottw@gmail.com
Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
784104659.042.png
 
Chapter 1. Welcome to Design Patterns Page 1
Intro to Design Patterns
5
:HOFRPHWR
4
4
'HVLJQ3DWWHUQV
1RZWKDWZH·UHOLYLQJ
LQ2EMHFWYLOOHZH·YHMXVWJRW
WRJHWLQWR'HVLJQ3DWWHUQV
HYHU\RQHLVGRLQJWKHP6RRQ
ZH·OOEHWKHKLWRI-LPDQG
%HWW\·V:HGQHVGD\QLJKW
SDWWHUQVJURXS
6RPHRQHKDVDOUHDG\VROYHG\RXUSUREOHPV ,QWKLVFKDSWHU\RX¶OOOHDUQ
ZK\DQGKRZ\RXFDQH[SORLWWKHZLVGRPDQGOHVVRQVOHDUQHGE\RWKHUGHYHORSHUVZKR¶YH
EHHQGRZQWKHVDPHGHVLJQSUREOHPURDGDQGVXUYLYHGWKHWULS%HIRUHZH¶UHGRQHZH¶OO
ORRNDWWKHXVHDQGEHQH¿WVRIGHVLJQSDWWHUQVORRNDWVRPHNH\22GHVLJQSULQFLSOHVDQG
ZDONWKURXJKDQH[DPSOHRIKRZRQHSDWWHUQZRUNV7KHEHVWZD\WRXVHSDWWHUQVLVWR ORDG
\RXUEUDLQ ZLWKWKHPDQGWKHQ UHFRJQL]HSODFHV LQ\RXUGHVLJQVDQGH[LVWLQJDSSOLFDWLRQV
ZKHUH\RXFDQ DSSO\WKHP ,QVWHDGRI FRGH UHXVHZLWKSDWWHUQV\RXJHW H[SHULHQFH UHXVH
WKLVLVDQHZFKDSWHU
Chapter 1. Welcome to Design Patterns
Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra
ISBN: 0596007124 Publisher: O'Reilly
Prepared for Ann Cherkis, Safari ID: maottw@gmail.com
Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
784104659.043.png 784104659.001.png 784104659.002.png 784104659.003.png
 
Chapter 1. Welcome to Design Patterns Page 2
6LP8'XFN
1\[\IZ\ML_Q\PI[QUXTM;QU=,]KSIXX
2WM_WZS[NWZIKWUXIVa\PI\UISM[IPQOPTa[]KKM[[N]TL]KSXWVL
[QU]TI\QWVOIUM ;QU=,]KS <PMOIUMKIV[PW_ITIZOM^IZQM\aWN
L]KS[XMKQM[[_QUUQVOIVLUISQVOY]IKSQVO[W]VL[<PMQVQ\QIT
LM[QOVMZ[WN\PM[a[\MU][ML[\IVLIZL77\MKPVQY]M[IVLKZMI\ML
WVM,]KS[]XMZKTI[[NZWU_PQKPITTW\PMZL]KS\aXM[QVPMZQ\
'XFN
$OOGXFNV TXDFNDQGVZLPWKH
VXSHUFODVVWDNHVFDUHRIW KH
LPSOHPHQWDWLRQFRGH
TXDFN
VZLP
GLVSOD\
27+(5GXFNOLNHPHWKRGV
0DOODUG'XFN
5HGKHDG'XFN
GLVSOD\^
ORRNVOLNHDPDOODUG`
GLVSOD\^
ORRNVOLNHDUHGKHDG`
1V\PMTI[\aMIZ\PMKWUXIVaPI[JMMV]VLMZQVKZMI[QVOXZM[[]ZM
NZWUKWUXM\Q\WZ[)N\MZI_MMSTWVOWNN[Q\MJZIQV[\WZUQVO
[M[[QWVW^MZOWTN\PMKWUXIVaM`MK]\Q^M[\PQVSQ\¼[\QUMNWZIJQO
QVVW^I\QWV<PMaVMML[WUM\PQVO ZMITTa QUXZM[[Q^M\W[PW_I\\PM
]XKWUQVO[PIZMPWTLMZ[UMM\QVOQV5I]Q VM`\_MMS
&KDSWHU
Chapter 1. Welcome to Design Patterns
Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra
ISBN: 0596007124 Publisher: O'Reilly
Prepared for Ann Cherkis, Safari ID: maottw@gmail.com
Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
784104659.004.png 784104659.005.png 784104659.006.png 784104659.007.png 784104659.008.png 784104659.009.png 784104659.010.png 784104659.011.png 784104659.012.png 784104659.013.png 784104659.014.png 784104659.015.png 784104659.016.png 784104659.017.png 784104659.018.png 784104659.019.png 784104659.020.png 784104659.021.png
 
Chapter 1. Welcome to Design Patterns Page 3
LQWUR WR 'HVLJQ3DWWHUQV
*]\VW__MVMML\PML]KS[\W.4A
<PMM`MK]\Q^M[LMKQLML\PI\ÆaQVOL]KS[Q[R][\_PI\\PM
[QU]TI\WZVMML[\WJTW_I_Ia\PMW\PMZL]KS[QUKWUXM\Q\WZ[
)VLWNKW]Z[M2WM¼[UIVIOMZ\WTL\PMUQ\¼TTJMVWXZWJTMU
NWZ2WM\WR][\_PQX[WUM\PQVO]XQVI_MMS¹)N\MZITTº[IQL
2WM¼[JW[[¹PM¼[IV77XZWOZIUUMZ PW_PIZLKIVQ\JM'º
,MXVWQHHGWRDGGDÁ\
PHWKRGLQWKH'XFNFODVVDQG
WKHQDOOWKHGXFNVZLOOLQKHULWLW
1RZ·VP\WLPHWRUHDOO\VKRZP\
WUXH22JHQLXV
-RH
:KDWZHZDQW
'XFN
TXDFN
VZLP
GLVSOD\
IO\
27+(5GXFNOLNHPHWKRGV
0DOODUG'XFN
5HGKHDG'XFN
GLVSOD\^
ORRNVOLNHDPDOODUG`
GLVSOD\^
ORRNVOLNHDUHGKHDG`
\RXDUHKHUH
Chapter 1. Welcome to Design Patterns
Head First Design Patterns By Eric Freeman, Elisabeth Freeman, Bert Bates, Kathy Sierra
ISBN: 0596007124 Publisher: O'Reilly
Prepared for Ann Cherkis, Safari ID: maottw@gmail.com
Print Publication Date: 2004/10/25 User number: 1673621 Copyright 2008, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
784104659.022.png 784104659.023.png 784104659.024.png 784104659.025.png 784104659.026.png 784104659.027.png 784104659.028.png 784104659.029.png 784104659.030.png 784104659.031.png 784104659.032.png 784104659.033.png 784104659.034.png 784104659.035.png 784104659.036.png 784104659.037.png 784104659.038.png 784104659.039.png 784104659.040.png
 
Zgłoś jeśli naruszono regulamin