posted by Jared White on Wed 7th May 2003 07:13 UTC
IconWelcome back to Part 2 of Cocoa 101: Object-Oriented Programming for the Masses! I received a lot of great feedback on my previous article, and I'm looking forward to sharing with you once again what I've learned about Cocoa and the Objective-C language. If you missed Part 1 of this tutorial, read it here.

To start off Part 2, I'd like to take just a brief moment to explain why I picked this title (Object-Oriented Programming for the Masses) for my article. I believe that Cocoa is the easiest and most logical method of GUI-based, object-oriented application programming available in a mainstream operating system. While many programming experts have welcomed Cocoa with open arms because of its RAD (Rapid Application Development) qualities and powerful foundation classes, I see its major strength as being a window of opportunity for regular "Joe" users with some technical computer skills to "make the leap" and become software producers, not just software consumers. And no, I'm not just talking through my hat. The amount of innovation I'm seeing right now in the Mac OS X software community is staggering, and much of it is coming from people who have slowly grown into the role of being a software developer, not people with 20+ years experience in programming and boasting several degrees in computer science. Though the fruits of my own labor have yet to be shown to the public, slowly but surely I find myself growing into the role of software developer as well. And I can easily claim that Cocoa is the reason, the only reason, that this has occurred.

Now if you'll recall, last time I introduced you to a few of the basics of Objective-C. In particular, the fact that every Objective-C object belongs to a class. Also, I stated that the concept of encapsulation is important in object-oriented programming -- that is, the implementation of an object is hidden behind its interface. That's where I left off previously, and that's where we'll pick up the trail this time.

In spite of all that was presented in Part 1, I missed showing you one very important thing: exactly how to define a class in code. This is because it's best to know a bit more about Cocoa before you can understand how that process works. So I'll use this opportunity to introduce a few of the basics of the Cocoa framework, as well continue on with our exploration of Objective-C.

Remember, every Objective-C class features at least one of these attributes: class methods (for the class objects), instance methods (for the regular object instances), and instance variables. So how exactly is a class definition created? Objective-C typically follows the grand C tradition of splitting up groups of code (in this case, objects) into two files: a header file and the actual code file. In Objective-C, this usually translates as: the interface file and the implementation file. For example, a MyPerson class would be defined using two files: MyPerson.h and MyPerson.m. The .h is the standard C header extension, and the .m stands for "Objective-C code module".

Table of contents
  1. "Page 1"
  2. "Page 2"
  3. "Page 3"
  4. "Page 4"
  5. "Page 5"
e p (0)    24 Comment(s)

Technology White Papers

See More