Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@interface and @protocol explanation?

Tags:

objective-c

I would like to know what the @interface in objective C is? is it just where the programmer want to declare the variables, class name or method names...? I am not sure whether it is like interface in Java. And about the @protocol in objective C as well. It seems like the interface in Java more. Could anyone give me detail explanation please. I truly appreciate it.

like image 236
Rocker Avatar asked Nov 05 '09 08:11

Rocker


People also ask

What are the different interface protocols?

Some low level protocols are TCP, UDP, IP, and ICMP. Some familiar examples of application layer protocols, built on these lower protocols, are HTTP (for accessing web content), SSH, TLS/SSL, and FTP. Port: A port is an address on a single machine that can be tied to a specific piece of software.

What is the difference between protocol and service interface?

A protocol is a set of rules for communication within a layer. A service is what the layer provides to the layer above it through an interface.

What is communication protocol and its types?

A communication protocol is a system of rules that allows two or more entities of a communications system to transmit information via any kind of variation of a physical quantity. The protocol defines the rules, syntax, semantics and synchronization of communication and possible error recovery methods.

What is an interface in data communication and networking?

A network interface is the point of interconnection between a computer and a private or public network. A network interface is generally a network interface card (NIC), but does not have to have a physical form.


1 Answers

An interface is where you define the attributes and operations of class. You must set out the implementation too.

A protocol is like an interface for java.

e.g.

@protocol Printing     -(void) print; @end 

can be implemented

by declaring (confusingly in the interface)

@interface Fraction: NSObject <Printing, NSCopying> { //etc.. 

The confusing thing for java developers is that the curly braces {} are not the end of the interface e.g.

@interface Forwarder : Object {     id recipient;  } //This is not the end of the interface - just the operations   - (id) recipient; - (id) setRecipient:(id) _recipient;  //these are attributes.  @end //This is the end of the interface 
like image 112
Johnno Nolan Avatar answered Oct 11 '22 12:10

Johnno Nolan