Objective-c language and gnustep base library programming manual


















Anyone wishing to write documentation or completely revise the following please get in touch with one of the GNUstep maintainers or the general discussion mailing list. This is the reference documentation for our library suite. If you find a blank, please send an update to the maintainer. All our documentation is on the ftp site as a compressed tar file in the docs directory.

For reference, we have an archived version of the original OpenStep specification. This is legacy documentation for look-up purposes. In the above example, we specify that the socket port name server is used to register the name for the connection In the telephone directory example, the code to obtain the proxy from any host on the network would be:. With this additional line of code in the client program, you can now construct a simple Objective-C statement to communicate with the remote object.

A client process does not need to know the class of a remote server object to avoid run-time errors, it only needs to know the messages to which the remote object responds. This can be determined by the client at run-time, by asking the server if it responds to a particular message before the message is sent.

A further advantage is gained at compile time, when the compiler will issue a warning if the server fails to implement any method declared in the protocol, or if the client contains any message to which the server cannot respond. The protocol is saved to a header file and then included in both client and server programs with the usual compiler include directive. Only the server program needs to implement the methods declared in the protocol.

To enable compiler checking in the client program, extend the type declaration for the proxy to this protocol, and cast the returned proxy object to the same extended type.

In the telephone directory example, if the declared protocol was TelephoneDirectory , declared in header file protocolHeader. For example, proxyForDirectory at the client could be a proxy for an instance of the TelephoneDirectory class at the server, and this class could implement the TelephoneDirectory protocol. Here we provide the rest of the code needed for client and server to actually run the above example.

To get this running, all you need do is create two directories, one for the client and one for the server. Each directory will hold a makefile, the client or server source code, and a copy of the protocol header file. When the files compile, first run the server and then the client.

What happens when you run the client without the server? How would you display a "No Server Connection" warning at the client? You might wonder how the client finds the server, or, rather, how it finds the directory the server lists itself in. For the default connection type a connection only usable on the local host between processes run by the same person , a private file or the registry on ms-windows is used to hold the name registration information. One difference you may have noticed in the example we just looked at from other remote method invocation interfaces such as CORBA and Java RMI was that there are no stub classes.

The source of this great boon is described at the end of this chapter: Language Support for Distributed Objects. Here are the requirements we will implement:. Two protocols will therefore be required, one for the methods implemented at the server and one for those implemented at the client.

Have a look at the program code in the following sections and added comments. Can you work out what is happening at the server and client? If you have any difficulties then refer to the relevant sections in this manual, or to class documentation here or at the Apple web site. We have chosen GameClient as the name of both the protocol adopted at the client and the class of the responding client object.

When you define a new class you can base it on an existing class. You are then free to add instance variables and methods, or even modify inherited methods, to change the behavior of the new class how it reacts to messages. Unlike functions in a procedural program such as C, where every function must have a unique name, a method or instance variable in one class can have the same name as that in another class. This means that two objects could respond to the same message in completely different ways, since identically named methods may do completely different things.

A draw message sent to a rectangle object would not produce the same shape as a draw message sent to a circle object. An object hides its instance variables and method implementations from other parts of the program.

This encapsulation allows the programmer that uses an object to concentrate on what the object does rather than how it is implemented. Also, providing the interface to an object does not change the methods of an object and how they respond to received messages then the implementation of an object can be improved without affecting any programs that use it. Due to polymorhism, the method performed in response to a message depends on the class type of the receiving object.

In an OO program the type, or class, of an object can be determined at run time dynamic typing rather than at compile time static typing. The method performed what happens as a result of this message can then be determined during program execution and could, for example, be determined by user action or some other external event.

Binding a message to a particular method at run time is known as dynamic binding. Objective-C is a powerful object-oriented OO language that extends the procedural language ANSI C with the addition of a few keywords and compiler directives, plus one syntactical addition for sending messages to objects.

During compilation of Objective-C source code, OO extensions in the language compile to C function calls to the runtime library. It is the runtime library that makes dynamic typing and binding possible, and that makes Objective-C a true object-oriented language.

Since Objective-C extends ANSI C with a few additional language constructs the compiler directives and syntactical addition , you may freely include C code in your Objective-C programs. In fact an Objective-C program may look familiar to the C programmer since it is constructed using the traditional main function.

Objective-C source files are compiled using the standard GNU gcc compiler. The compiler recognises Objective-C source files by the. The -lobjc compiler option is required for linking an Objective-C program to the runtime library. The GNUstep make utility provides an alternative and simple way to compile large projects, and this useful utility is discussed in the next section.

Objective-C has these too, but you do not need them as often as in Java, even though Objective-C is compiled while Java is interpreted. They aimed to minimally incorporate the object-oriented features of Smalltalk into C. NeXT implemented its own compiler by building on the gcc compiler, modifications that were later contributed back to gcc in No less than three runtime libraries were subsequently written to serve as the GNU runtime; the one currently in use was developed by Danish university student Kresten Krab Thorup.

This in turn influenced the design of the NeXTstep class libraries, which are what GNUstep itself is ultimately based on.

After NeXT exited the hardware business in the early s, its Objective-C class library and development environment, NeXTstep , was renamed OpenStep and ported to run on several different platforms. This API consists of two parts: the Foundation , a collection of non-graphical classes for data management, network and file interaction, date and time handling, and more, and the AppKit , a collection of user interface widgets and windowing machinery for developing full-fledged graphical applications.



0コメント

  • 1000 / 1000