About site: Programming/Languages/Objective-C - Objective-C is Fun
Return to Computers also Computers
  About site: http://www.gnustep.org/resources/ObjCFun.html

Title: Programming/Languages/Objective-C - Objective-C is Fun A simple introduction to Objective-C, from the GNUstep project. By Adam Fedor.
ETC_Support Specializing in SUN computers and servers.

Concord_Associates Performance improvement for chemical, refinery, pipeline, and natural gas operations. Human Factors, Safety, Reliability, Training, Procedures, ConOps, Maintenance, Performance Measures, Incident Inve

Churchway_Business_Computers Sage solutions centre, the best in shropshire for your purchases and for support.

RFC_0207 September Network Working Group Meeting. A. Vezza. August 1971.

htmlPlayground HTML, CSS Reference by example. Offers online HTML code editor to edit examples and experiment with the code.

Apple_-_Open_Source The "open source" portions of Apple technologies, including Darwin, aka the core of Mac OS X.


  Alexa statistic for http://www.gnustep.org/resources/ObjCFun.html





Get your Google PageRank






Please visit: http://www.gnustep.org/resources/ObjCFun.html


  Related sites for http://www.gnustep.org/resources/ObjCFun.html
    Spam_Laws_-_US_and_European United States, European Union, and other countries' laws and pending legislation regarding unsolicited commercial email.
    Rackmount_Computers Builds industrial computer systems for the scientific and engineering fields. Offers a wide variety of rackmount periperhals
    Website_Meta_Language A free markup generation toolkit for Unix. News, full documentation, mailing list, examples. [Unix]
    BBSzilla An extension for Mozilla-based browsers that allows the user to connect to Hotline servers and other similar Bulletin Board Systems.
    Streamline_Automation_Pty_Limited Developers of autoOffice, an add-in application, which contains a package of automated templates to comprises of four of the most common templates in use by most organisations - letter, fax, internal
    Ted_Nelson,_Hypertext_Pioneer ZDTV article describing his work on Xanadu. (August 12, 1998)
    SmartSVN_-_Java-based_Subversion_Client Cross-platform SVN client. Free (for non-commercial and commercial use) and professional versions available.
    www_bcarter_com This site has a large number of useful and in-depth PowerBuilder programming tips. The tips can be searched by keyword, topic, and date. Use the Table of Contents link.
    t-_Sofotex Directory of freeware and shareware download sites, with rated descriptions of available programs, utilities, and scripts.
    Zeitgeist_Design Denver, Colorado based company offers high-end print and multimedia design including Flash animation, HTML, JavaScript and ASP development.
    FRIUG The Front Range IBM Users Group is a not for profit organization comprised of users of IBM AS/400 and other mid-range IBM computer systems.
    Chipmunk_Scripts A free collection.
    ScriptDungeon_-_Free_PHP_Scripts Collection of free PHP scripts.
    3GP_For_Free Offers videos for mobile phones.
    This_Funs_For_You A catalogue of fun, Flash, applets, tributes, holidays and occasions.
    Site_Vigil A sophisticated web site monitoring tool that checks access to pages, unexpected surges or lulls in visitor traffic to your web site. Check all links and pages on a web site.
    Eclectic_Designs Web design and development, site promotion and marketing, banner design, and hosting.
    Privacy_Secrets_of_MicroSoft\'s_Internet_Explorer Security and internet privacy issues of Global Histories, Cookies, and Cache while browsing with Mac Explorer 5.0
    High_Voltage_Internet Offers design, hosting and custom programming. Located in California, United States.
    MS-TNEF_Degenerator Web-based program to decode Microsoft Outlook-formatted e-mail attachments.
This is websites2007.org cache of m/ as retrieved on 2008.08.21 websites2007.org's cache is the snapshot that we took of the page as we crawled the web. The page may have changed since that time.
GNUstep: Fun with Objective-C(Note: This article originally appeared in cscene)

Objective-C is Fun

by Adam FedorObjective-C is a language based upon C, with a few additionsthat make it a complete, object-oriented language. Why do I thinkObjective-C is fun? Precisely because of this emphasis onsimplicity. Absolutely nothing was added to the language unless itreally made a big improvement on the useability of Objective-C.Fun, of course, can also lead to danger. And there is plenty tobeware of with Objective-C. Since Objective-C doesn't try toimprove the C language, you have to deal with all the faults andcaveats of C. In addition, the philosophy of Objective-C is toallow for a great deal of flexibility, leaving the programmer towatch out for potential problems rather than forcing variousrestrictions. For instance, Objective-C provides an objectdefinition that is completely untyped. This is the idvariable type, which stands for any object. With this type, you cansend a message to any object, without knowing at all what theobject is or what it can do.Like C, this flexibility allows you to perform great tricks,while forcing the programmer to introduce his own conventions toprevent errors. But, ahh, there is fun in danger, isn't there?Note: In the following article, I describe a particular variantof Objective-C known as OpenStep (or GNUstep, the freeimplementation of OpenStep). This is by far the most popularimplementation of Objective-C (there is no standard Objective-Clanguage yet...).

An Introduction

In truth, there is actually only one syntax addition to thelanguage -- the syntax for sending a message to an object: [anObject doSomethingWith: anotherObject];This statement simply sends the message doSomethingWith: toanObject, with an argument of anotherObject. AnObjective-C message call can be used anywhere a C statement can beused, such as in a conditional statement or within anotherObjective-C message. On compilers that support it, Objective-Cmessages can be mixed in C++ code, allowing the programmer to pickand choose the best aspects of either language.In addition, there are some keywords that have been added toallow for the definition and implementation of classes, such as thedefinition for the class of which anObject is amember:@interface MyClass : NSObject{ int aVariable; id subObject;}+ alloc;+ defaultObject;- init;- (int) doSomethingWith: (id)anotherObject;@endHere, @interface tells the compiler we are defining aninterface for the class named MyClass, which is a subclassof the class NSObject. NSObject is the root classused by GNUstep (The traditional Objective-C root classObject, is not used at all in GNUstep, although it isavailable). The root class is not a subclass of any other class.Although it is not required that a class descend from a root classlike NSObject, this hierarchy is so firmly ingrained inthe language, that it is rare to see classes that are a root classby themselves. The root class contains some of the most basic andoften used functionality, which gives you the advantage of knowingthat all your classes will responds to these basic messages. Out ofthe 300 or so classes in the GNUstep core library, only two areroot classes.The curly brackets after the class definition enclose the datathat is encapsulated in the class. These variables are calledinstance variables, because they are variables that belongto an instance of a class.The rest of the interface defines the methods implemented by theclass. A method is a description of a message a class responds to.A '+' indicates a class method. Class methods are oftencalled factory methods, because typically a factory methodis used to create or manufacture instances of the class.The most popular class method is alloc, which allocatesspace for an instance of the class (but does not initialize theclass -- that is usually reserved for the instance methodinit). A '-' indicates an instance method. Forexample, the doSomethingWith: method defined above takes oneargument, the object anotherObject, and returns aninteger. Class messages can only be sent to a class. Instancemessages can only be sent to an instance of a class.

Dynamic Binding

Objective-C is a language that implements true dynamicbinding (which is required for a language to be trulyobject-oriented). This means that messages sent to an object aren'tbound to a specific function implementation in a specificclass until the program is actually run. Stating this another way,the programmer does not know how an object will react to aspecific message until the program is actually run.Dynamic binding comes about because in every Objective-Cprogram, there is a runtime that works behind the scenesto connect a specific message with a specific object. Every time amessage like doSomethingWith: is sent to an object, theObjective-C runtime looks up the definition of the class of theobject, finds the function (method) that corresponds to the messagedoSomethingWith:, and then calls that function.It may seem like this type of lookup could really slow a programdown. In practice, however, most runtimes are optimized for thissort of lookup, and in general, it can be shown that message lookupis often not the dominant time factor of a program (particularly inGUI programs). Anywhere that time is critical, it's possible inObjective-C to pre-bind a message to its implementation,thus avoiding the expensive message lookup.An interesting aspect of a method definition, is that once amethod is defined, that method name and definition are, in a senseglobal, and can be used anywhere. For instance, say I hadan object newObject that did not recognize thedoSomethingWith: message. Well I could send the message tothe object anyway, and the compiler would not complain aboutit: id newObject; // could be any object; newObject = [[NewObject alloc] init]; // create and initialize the object [newObject doSomethingWith: anotherObject]; // send it a message.Only when the program was run would the Objective-C runtimediscover that newObject did not recognize thedoSomethingWith: message. However, instead of immediatelyissuing an error, the runtime instead sends another message tonewObject, called the forwardInvocation: message. Thisgives newObject a chance to handle messages sent to it that itdoesn't understand. In this case, if newObject knew about anObject,it could forward the message on to anObject and let it handle themessage:- (void) forwardInvocation: (NSInvocation*)anInvocation{ if ([anObject respondsToSelector: [anInvocation selector]]) return [anInvocation invokeWithTarget: anObject]; else return [self doesNotRecognizeSelector: [anInvocation selector]];}Here, the variable self refers to the object whichreceived the message (similar to the this variable inC++). anInvocation is another object which contains allthe information about the message that was sent, including the nameof the message (the selector) and any arguments.This type of usage is called delegation, and it is a powerfulmethod of implementing various different constructs such asmultiple inheritance, journaling, and dispatching messages todynamically loaded code.Incidentally, there are proper ways to handle unrecognizedmessage, using Protocols, that allow for compile time checking andmore robust code. Most programmers avoid defining un-typed objectsunless it's really useful. A better way to write the first codesegment would be: NewObject *newObject; // newObject will be an instance of the NewObject class newObject = [[NewObject alloc] init]; // create and initialize the object [newObject doSomethingWith: anotherObject];In this case, the compiler would issue a warning stating thatnewObject does not respond to the messagedoSomethingWith:.

Implementation

I've already given an example of how to implement a method withthe forwardInvocation: method. That example wasn'tentirely correct. In Objective-C, a method implementation must beassociated with a certain class by enclosing the implementationbetween the keywords @implementation and@end.@implementation MyClass- (int) doSomethingWith: anotherObject{ return [anotherObject multiply: 3 by: 4];}@endThe @implementation keyword, is a counterpart to the@interface keyword (Note that it is not necessary toindicate that MyClass is a subclass of NSObject. The compileralready knows this from the interface definition). You canimplement as many methods as you like within an@implementation block (even methods that were notdescribed in the class interface).Methods that are implemented in the implementation section butare not described in the interface become, in essence, privatemethods that can only be used by that class and not by anotherclass.

Power through Customization

One of the most frustrating aspects of using classes written byother people is that these classes often don't contain some keyfunctionality that you need. One way to add this functionality(assuming you don't have the source to the original class, or don'twant to change it for some other reason), is to simply make asubclass and implement the methods you need in that class. But thiscreates another problem. Now you have to tell everyone else to useyour particular subclass and not the original class. Or what ifsomeone else has already subclassed this class and added differentfunctionality. How do you combine the two subclasses?Objective-C provides a very simple and elegant way to addfunctionality to an existing class using Categories. Acategory is defined simply with an @interface line and thename of the category (e.g. MyAdditionalMethods):@interface MyClass (MyAdditionalMethods)- (int) doSomethingWith: thisObject andThenWith: thatObject;@endThe additional methods are then implemented in a complementary@implementation section. There is one restriction,however. You can't define additional instance variables, whichwould change the amount of data held by the class. Other than thisrestriction, the things you can do with categories is incredible(and bizarre). For instance, if a method is defined both in themain class interface and a category, the category implementationwins. A message sent to the class will use the categoryimplementation and ignore the original class implementation. If amethod is defined in two separate categories, the implementationthat is used is indeterminate, since you never know which categorywill be loaded first. In a situation where dynamic loading is used,this sort of behavior can create all sorts of headaches for asecurity conscious programmer...Most often, however, categories are used to implement additionalfunctionality that may be useful to only one part of the program.For instance, some additional methods may be defined to allow aclass to better interact with the GUI section of the program, orthe distributed objects section of the program.

And More...

I've only touched on a few of the features of Objective-C. Ialso haven't answered a lot of typical first-time Objective-C userquestions, like why is the allocation of space for a class(alloc) separated from the initialization of the class(init)? How do you get rid of an object once your done withit (garbage collecting)? Future articles might tackle thesequestions.To learn more, I'd encourage you to visit the GNUstep home page(www.gnustep.org) or the AppleDevelopers page (
 

A

simple

introduction

to

Objective-C,

from

the

GNUstep

project.

By

Adam

Fedor.

http://www.gnustep.org/resources/ObjCFun.html

Objective-C is Fun 2008 August

dvd rental

dvd


A simple introduction to Objective-C, from the GNUstep project. By Adam Fedor.

Rules




© 2008 Internet Explorer 5+ or Netscape 6+

Recommended Sites: 1. Arts - Business - Computers - Games - Health - Home - Kids and Teens - News - Recreation - Reference - Regional - Science - Shopping - Society - Sports - World Miss Gallery - Top Anime Hentai - DVD rental by mail - Wills - 0% Balance Transfers - Turbo Tax - 0 Credit Cards - Myspace Happy Birthday Comments
2008-08-21 16:48:26

Copyright 2005, 2006 by Webmaster
Websites is cool :) 277Bramy - Tooth Whitening - Akwarium - Hotel Goteborg - Klimatyzacja