Cocoa (software)
Cocoa is Apple Computer's native object-oriented application programming environment for the Mac OS X operating system. It is one of five major programming environments available for Mac OS X; the others are Carbon, Classic, BSD, and Java. (Environments such as Perl and Python are considered minor environments because they are not generally used for full-fledged application programming. There are, of course, exceptions to this rule.)The name is also sometimes used to describe the development environment as well, consisting primarily of Project Builder and Interface Builder. (With the release of Mac OS X "Panther" in late 2003, Project Builder will be replaced by a new Cocoa IDE, Xcode. This is not accurate, as other environments such as CodeWarrior and a few other compilers also support development for the API. For consumers the term refers to applications written with the interface and features inherent to Cocoa applications. This usually means they are written mostly in Cocoa, but there are exceptions since Cocoa can be combined with other types of development.
| Table of contents |
|
2 Main frameworks 3 Memory management 4 External links |
Cocoa history
Cocoa is derived from the NeXTSTEP and OPENSTEP programming environments developed by NeXT in the late 1980's. Apple acquired NeXT in December, 1996, and subsequently went to work on the Rhapsody operating system that was supposed to be the direct successor of OPENSTEP and use OPENSTEP technology proper, and have an emulation base for Mac OS applications, which was termed Blue Box. The OPENSTEP base of libraries and binary support was termed Yellow Box. However, the focus on Rhapsody lessened, and Apple soon shifted to developing Mac OS X.
Much of the work that went into developing OPENSTEP was applied to the development of Mac OS X. Cocoa is the most visible part of that synergy. There are, however, some very important fundamental differences. The most visible of which is that NeXTSTEP and OPENSTEP used Display PostScript for on-screen display of text and graphics, while Cocoa depends on Apple's Quartz (which uses PDF). Cocoa also has some level of internet support (NSUrl classes, and others), while under OPENSTEP one managed network connections through NSFileHandle classes and Berkeley sockets.
Main frameworks
Cocoa consists of two Objective C libraries called frameworks. Frameworks are a construct unique to the NeXTSTEP/OpenStep/Cocoa family of programming environments. They are functionally very similar to shared libraries, which are often referred to by the acronym DSO, for dynamic shared object, or DLL, for dynamically linked library. A framework consists of a compiled object that can be dynamically loaded into a program's address space at run-time, along with the associated resources, header files, and documentation.
- Application Kit or AppKit is directly descended from the original NeXTSTEP Application Kit. It contains code with which programs can create and interact with graphical user interfaces. NSWindow and NSButton are examples of AppKit classes.
- Foundation first appeared in OpenStep. It is a generic object-oriented library providing string and value manipulation, containers and iteration, distributed computing, event handling, networking, and other functions that are not directly tied to the graphical user interface. NSString, NSDictionary and NSURLHandle are examples of Foundation classes.
Memory management
One feature of the Cocoa environment that is, if not unique, certainly unusual is its facility for managing dynamically allocated memory. Cocoa's NSObject class, from which all Cocoa classes, both vendor and user, are derived, implements a reference counting scheme for memory management. Every object has a retain method and a release method, and an instance variable accessible through the retainCount accessor method. A newly allocated object, created with alloc, has a retain count of one. Sending that object a retain message increments the retain count, while sending it a release message decrements the retain count. When an object's retain count reaches zero, it is deallocated and its memory is freed. (Deallocation is to Objective C objects as destruction is to C++ objects. The dealloc method is functionally equivalent to a C++ destructor.)In addition to manual reference counting, application programmers may choose to make use of autorelease pools. Sending an object an autorelease message puts that object's deallocation under the control of the thread's global autorelease pool. The autorelease pool releases an object some time after program flow has passed out of the block where that object was autoreleased.
Cocoa gives the programmer the choice of whether to manually manage his objects or not. Opinions on this are divided. Some say that Cocoa's memory management is superior because it allows the programmer to have precise control over when his objects are deallocated, but does not burden him with the necessity of doing so for every object a program allocates. Others say that the whole mess is unnecessary, and that Java-style automatic garbage collection is superior, because it removes the possibility of programmer error in memory management.
Java bindings for the Cocoa frameworks are also available. While the frameworks themselves are written in Objective C, and Objective C is presently the preferred language for Cocoa programming, Cocoa applications can be written in Java.
An open source implementation of the OpenStep specification is available under the name GNUstep.