Learning Cocoa with Objective-C
|
| Price: |
Product Description
Learning Carbon was created by the technical writers, engineers, support specialists, and other professionals at Apple Computer, Inc., who are committed to making Mac OS X a superior platform for innovation, productivity, and enjoyment. These professionals have diligently collected, compiled, and edited the information in this books to ensure that it is a useful resource for Mac OS X developers. This is the "must-have" book for people who want to develop applications for Mac OS X, and is the only book approved and reviewed by Apple engineers. Based on the Jaguar release of Mac OS X 10.2, this new edition of Learning Cocoa covers the latest updates to the Cocoa frameworks, including examples that use the Address Book and Universal Access APIs. Also included with this edition is a handy quick reference card, charting Cocoa's Foundation and AppKit frameworks, along with an Appendix that includes a listing of resources essential to any Cocoa developer - beginning or advanced. Revised and updated, this new edition begins with some simple examples to familiarize you with the basic elements of Cocoa programming as well Apple's Developer Tools, including Project Builder and Interface Builder. After introducing you to Project Builder and Interface Builder, it brings you quickly up to speed on the concepts of object-oriented programming with Objective-C, the language of choice for building Cocoa applications. From there, each chapter presents a different sample program for you to build, with easy to follow, step-by-step instructions to teach you the fundamentals of Cocoa programming. The techniques you will learn in each chapter lay the foundation for more advanced techniques and concepts presented in later chapters. You'll learn how to: use Apple's suite of Developer Tools, including Project Builder and Interface Builder; Build single- and multiple-window document-based applications; manipulate text data using Cocoa's text handling capabilities; draw with Cocoa; add scripting functionality to your applications; localize your application for multiple language support; polish off your application by adding an icon for use in the Dock, provide Help, and package your program for distribution; each chapter ends with a series of examples, challenging you to test your newly-learned skills by tweaking the application you've just built, or to go back to an earlier example and add to it some new functionality. Solutions are provided in the Appendix, but you're encouraged to learn by trying. Extensive programming experience is not required to complete the examples in the book, though experience with the C programming language will be helpful. If you are familiar with an object-oriented programming language such as Java or Smalltalk, you will rapidly come up to speed with the Objective-C language. Otherwise, basic object-oriented and language concepts are covered where needed. Based on the Jaguar release of Mac OS X 10.2, this new edition of "Learning Cocoa" covers the latest updates to the Cocoa frameworks, including examples that use the Address Book and Universal Access APIs. Also included with this edition is a handy quick reference card, charting Cocoa's Foundation and AppKit frameworks, along with an Appendix that includes a listing of resources essential to any Cocoa developer - beginning or advanced.
Product Details
- Amazon Sales Rank: #470606 in Books
- Published on: 2002-09-20
- Original language: English
- Number of items: 1
- Binding: Paperback
- 384 pages
Editorial Reviews
From the Publisher
Based on the Jaguar release of Mac OS X 10.2, this new edition of Learning Cocoa covers the latest updates to the Cocoa frameworks, including examples that use the Address Book and Universal Access APIs. Also included with this edition is a handy quick reference card, charting Cocoa's Foundation and AppKit frameworks, along with an Appendix that includes a listing of resources essential to any Cocoa developer--beginning or advanced. This is the "must-have" book for people who want to develop applications for Mac OS X, and is the only book approved and reviewed by Apple engineers.
About the Author
James Duncan Davidson is a freelance author, software developer, and consultant focusing on Mac OS X, Java, XML, and open source technologies. He is the author of Learning Cocoa with Objective-C (published by O'Reilly & Associates) and is a frequent contributor to the O'Reilly Network online website as well as publisher of his own website, x180 (http://www.x180.net), where he keeps his popular weblog. Duncan was the creator of Apache Tomcat and Apache Ant and was instrumental in their donation to the Apache Software Foundation by Sun Microsystems . While working at Sun, he authored two versions of the Java Servlet API specification as well as the Java API for XML Processing. Duncan regularly presents at conferences all over the world on topics ranging from open source and collaborative development to programming Java more effectively. He didn't graduate with a Computer Science degree, but sees that as a benefit in helping explain how software works. His educational background is in Architecture (the bricks and mortar kind), the essence of which he applies to every software problem that finds him. He currently resides in San Francisco, California.
Excerpted from Learning Cocoa with Objective-C by James Duncan Davidson. Copyright © 2002. Reprinted by permission. All rights reserved.
CHAPTER 3 - Object-Oriented Programming with Objective-C
Object-oriented programming isn’t rocket science, but you can’t learn it overnight either. There is a lot of terminology - composed of words like "encapsulation" and "polymorphism" and phrases like "is-a" and "has-a" - that goes with the territory.
The concepts behind these terms are not terribly complicated, but they can be hard to explain. Like most useful fields of study, you must work with it a while before it all clicks together in your mind. As each concept becomes clear,you will gain a deeper understanding of the subject. That said,you don ’t have to understand everything about object-oriented programming on the first pass to make good use of the concepts.
In this chapter, we present the object-oriented concepts that matter most when working with Cocoa, along with quite a bit of hands-on practice using those concepts. If this is the first time you ’ve approached object-oriented programming, read carefully, but don’t worry if you don’t get everything at first. Just remember to flip back to this part of the book later if something didn’t sink in. If you already know a bit about object-oriented programming, then you should treat this as a refresher and see how Objective-C’s implementation of the object-oriented concepts with which you are familiar works.
Introducing Objects
Procedural programming divides the programming problem into two parts: data and operations on that data. Because all of the functionality of a procedural program works on the same set of data, the programmer must be very careful to manipulate the data of a program in such a way that the rest of the program can work correctly.
He must be aware of the entire program at a low level of abstraction so as not to introduce errors. As a procedural program grows in size, the network of interaction between procedures and data becomes increasingly complex and hard to manage.
Object-oriented programming (OOP), first developed in the 1960s,*restructures the programming problem to allow for a higher level of abstraction.It groups operations and data into modular units called objects. These objects can be combined into structured networks to form a complete program, similar to how the pieces in a puzzle fit together to create a picture. In contrast to procedural programming ’s focus on the interaction between data and functions,the design of objects and the interactions between those objects become the primary elements of object-oriented program design.
By breaking down complex software projects into small, self-contained,and modular units, object orientation ensures that changes to one part of a software project will not adversely affect other portions of the software. Object orientation also aids software reuse. Once functionality is created in one program,it can easily be reused in other programs.
Programming with objects is quite like working with real-world objects. Take an iPod, for example. It embodies both state and behavior. When you operate it, you don’t necessarily care how it works, as long as it works in the way that you expect.
As long as your iPod plays music when you tell it to and synchronizes your music collection with iTunes when you plug it into your computer, you’re happy. Object-oriented programming brings this same level of abstraction to programming and helps remove some of the impediments to building larger systems. To enjoy listening to music, you don’t have to know that iTunes and your iPod use the MP3 format;
you just put a CD into your computer and import the music into your collection.
iTunes and your iPod work together to download the music from your computer when you plug in the iPod.Figure 3-1 shows these components working together.
Classes of Objects
In the real world,there are often many objects of the same kind,or type. My iPod is just one of many iPods that exist in the world. In the lingo of object-oriented programming, each iPod is an instance. An instance of an object has its own state and leads an existence independent of all other instances. My iPod probably has a very different collection of music than yours does. †But just as all iPods have the same set of buttons —allowing the same set of operations (play, stop, etc.) — all instances of a particular object expose the same functionality to the outside world.
You specify an object by defining its class .Think of a class as a blueprint for making object instances. It provides all the information needed to build new instances of an object. Each class defines the internal variables that hold the data of an object instance and the ways, or methods, by which that data can be manipulated. These methods define the interface of the object. The interface is how other objects are allowed to use it.




