Pro Objective-C Design Patterns for iOS - Carlo Chung.pdf

(9581 KB) Pobierz
Pro Objective-C Design
Patterns for iOS
■■■
Carlo Chung
i
Pro Objective-C Design Patterns for iOS
Copyright © 2011 by Carlo Chung
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN-13 (pbk): 978-1-4302-3330-5
ISBN-13 (electronic): 978-1-4302-3331-2
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
President and Publisher: Paul Manning
Lead Editor: Douglas Pundick
Technical Reviewer: James Bucanek
Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan
Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Jeff Olson, Jeffrey
Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft,
Matt Wade, Tom Welsh
Coordinating Editor: Corbin Collins
Copy Editors: Mary Ann Fugate, Mary Behr
Compositor: MacPS, LLC
Indexer: BIM Indexing & Proofreading Services
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com,
or visit
www.springeronline.com.
For information on translations, please e-mail
rights@apress.com,
or visit
www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/info/bulksales.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at
www.apress.com.
Contents at a Glance
Contents .............................................................................................................. v
About the Author................................................................................................. x
About the Technical Reviewer ........................................................................... xi
Acknowledgments ............................................................................................ xii
Preface ............................................................................................................ xiii
Part I: Getting Your Feet Wet .............................................................................. 1
■Chapter
1: Hello, Design Patterns! .................................................................. 3
■Chapter
2: A Case Study: Designing an App .................................................. 19
Part II: Object Creation ..................................................................................... 45
■Chapter
3: Prototype ..................................................................................... 47
■Chapter
4: Factory Method ............................................................................ 63
■Chapter
5: Abstract Factory .......................................................................... 73
■Chapter
6: Builder ......................................................................................... 85
■Chapter
7: Singleton ...................................................................................... 97
Part III: Interface Adaptation .......................................................................... 107
■Chapter
8: Adapter ...................................................................................... 109
■Chapter
9: Bridge ........................................................................................ 127
■Chapter
10: Façade...................................................................................... 137
Part IV: Decoupling of Objects ........................................................................ 145
■Chapter
11: Mediator ................................................................................... 147
■Chapter
12: Observer................................................................................... 165
iii
■
CONTENTS AT A GLANCE
Part V: Abstract Collection ............................................................................. 183
■Chapter
13: Composite ................................................................................ 185
■Chapter
14: Iterator ..................................................................................... 201
Part VI: Behavioral Extension ......................................................................... 219
■Chapter
15: Visitor....................................................................................... 221
■Chapter
16: Decorator ................................................................................. 233
■Chapter
17: Chain of Responsibility ............................................................ 253
Part VII: Algorithm Encapsulation .................................................................. 263
■Chapter
18: Template Method ..................................................................... 265
■Chapter
19: Strategy ................................................................................... 281
■Chapter
20: Command ................................................................................. 293
Part VIII: Performance and Object Access ...................................................... 313
■Chapter
21: Flyweight ................................................................................. 315
■Chapter
22: Proxy ........................................................................................ 327
Part IX: State Of Object ................................................................................... 339
■Chapter
23: Memento .................................................................................. 341
Index ............................................................................................................... 361
iv
Zgłoś jeśli naruszono regulamin