ebook img

Cocoa design patterns PDF

457 Pages·2010·3.994 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Cocoa design patterns

Praise for Cocoa Design Patterns “This long-needed book is a great resource for Cocoa newcomers and veterans who want to get the why behind the what.The list of patterns gives historical perspective and answers many developer questions and the last three chapters—covering Core Data, AppKit,and Bindings—are a must-read;they reveal insights that might otherwise require hours of discussion with Apple engineers or access to source code.” —Tim Burks,Software Developer and Creator of the Nu Programming Language, www.programming.nu “This book is a comprehensive and authoritative treatment of design patterns and their practical applications in Cocoa projects.I recommend this book to anyone who wants to advance from intermediate to expert proficiency as a Macintosh developer.” —John C.Randolph,Vice President Engineering,Stealth Imaging,Inc. “Cocoa Design Patterns is a fantastic book that will show you the ins and outs of software design patterns,how Cocoa makes use of them,and how to apply them to your own applications for better,more robust,and more maintainable software.” —August Trometer,Owner of FoggyNoggin Software “Cocoa Design Patterns is superb! It is highly readable,thoroughly enjoyable,and filled to the brim with wisdom that will make you a more efficient and effective programmer. The authors utilize a consistent and self-contained approach to each chapter,making it easy to return to use as a reference.However,the material is so interesting and vital to Cocoa programmers that you’ll want to read it from cover to cover.” —David Mandell,Independent Developer “Erik and Donald’s book really helped me out with the conceptual side of program- ming.It caused me to realize where I was going wrong in my code and helped me sort out my design issues.” —Eoin Houlihan “This book is recommended for any programmer interested in a deeper understanding of Cocoa.Reading it might have helped me become a better software engineer in any object-oriented language.I’ll keep it handy as a constant reference and look forward to reading it again more carefully.” —Daryl Spitzer This page intentionally left blank Cocoa Design Patterns This page intentionally left blank Cocoa Design Patterns Erik M. Buck Donald A. Yacktman Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products Editor-in-Chief are claimed as trademarks. Where those designations appear in this book,and the publish- Karen Gettman er was aware of a trademark claim,the designations have been printed with initial capital Acquisitions Editor letters or in all capitals. Chuck Toporek The authors and publisher have taken care in the preparation of this book but make no Development expressed or implied warranty of any kind and assume no responsibility for errors or omis- Editor sions. No liability is assumed for incidental or consequential damages in connection with or Sheri Cain arising out of the use of the information or programs contained herein. Managing Editor The publisher offers excellent discounts on this book when ordered in quantity for bulk pur- Kristy Hart chases or special sales,which may include electronic versions and/or custom covers and Project Editor content particular to your business,training goals,marketing focus,and branding interests. JovanaSanNicolas- For more information,please contact Shirley U.S. Corporate and Government Sales Copy Editor (800) 382-3419 Language [email protected] Logistics,LLC For sales outside the United States,please contact Indexer Rebecca Salerno International Sales [email protected] Proofreader Apostrophe Editing Visit us on the Web: informit.com/aw Services Library of Congress Cataloging-in-Publication Data: Publishing Coordinator Buck,Erik M. Romny French Cocoa design patterns / Erik M. Buck,Donald A. Yacktman. Cover Designer Gary Adair p. cm. Compositor Includes bibliographical references and index. Jake McFarland ISBN 978-0-321-53502-3 (pbk. : alk. paper) 1. Cocoa (Application development environ- ment) 2. Object-oriented programming (Computer science) 3. Software patterns. 4. Mac OS. I. Yacktman,Donald A. II. Title. QA76.64.B82 2009 005.26’8—dc22 2009023288 Copyright © 2010 Pearson Education,Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright,and permission must be obtained from the publisher prior to any prohibited repro- duction,storage in a retrieval system,or transmission in any form or by any means,elec- tronic,mechanical,photocopying,recording,or likewise. For information regarding permis- sions,write to: Pearson Education,Inc. Rights and Contracts Department 501 Boylston Street,Suite 900 Boston,MA 02116 Fax (617) 671-3447 ISBN-13: 978-0-321-53502-3 ISBN-10: 0-321-53502-2 Text printed in the United States on recycled paper at R.R. Donnelley in Crawfordsville, Indiana. First printing September 2009 ❖ To my beloved wife,Michelle,who makes my life and every accomplishment possible,and to my children, Joshua,Emma,and Jacob,for their tireless support and understanding. —Erik M.Buck ❖ Dedicated to my wife Marcie for her patience and support and my boys,Joseph and William,for their never-ending curiosity about how and why things work the way they do. —Donald A.Yacktman ❖ Table of Contents I: One Pattern to Rule Them All 1 1 Model View Controller 2 MVC in Cocoa 4 Core Data Support for Model Subsystems 5 Application Kit Support for View Subsystems 6 Application Kit Support for Controller Subsystems 8 Cocoa’s Text Architecture 9 Cocoa’s Document Architecture 10 Cocoa Scriptability 13 Cocoa’s Preference Pane Architecture 14 Quartz Composer’s Architecture 15 The QTKit Architecture 15 Summary 15 2 MVC Analyzed and Applied 17 Non-MVC Design 17 Analysis of the Non-MVC Pay Calculator Design 21 MVC Design 22 Analysis of the MVC Pay Calculator Design 26 Summary 27 II: Fundamental Patterns 28 3 Two-Stage Creation 29 Motivation 29 Solution 31 Zones 31 Initializing Allocated Memory 32 Implementing the Designated Initializer 33 Using Zones in Initializers 35 Creating Temporary Instances 37 Examples in Cocoa 38 Consequences 42 Contents ix 4 Template Method 43 Motivation 43 Solution 44 Default Template Methods 45 Designing with Template Methods 46 Examples in Cocoa 47 Using the –drawRect: Template Method 47 Other Cocoa Template Methods 47 Consequences 51 5 Dynamic Creation 53 Motivation 53 Solution 53 Using Dynamic Creation 54 Dynamic Creation to Implement Plug-In Architectures 60 Examples in Cocoa 61 Consequences 62 6 Category 63 Motivation 63 Solution 64 Informal Protocols 67 The Anonymous Category 68 Code Organization 69 When to Use Categories Versus Subclassing 69 Examples in Cocoa 70 Using Categories for Organization 70 Using Categories for Informal Protocols 71 Using Categories for Framework Division 74 Consequences 74 The Clash of Methods 74 Replacing Methods 75 Software Maintenance 76

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.