Protocol (object-oriented programming)

From Wikipedia, the free encyclopedia

Jump to: navigation, search

In object-oriented programming, a protocol or interface is what or how unrelated objects use to communicate with each other. These are definitions of methods and values which the objects agree upon in order to cooperate.

For example, in Java (where protocols are termed interfaces), there is the Comparable interface specifies a method compareTo() which implementing classes should implement. So, this means that a separate sorting method, for example, can sort any object which implements the Comparable interface, without having to know anything about the inner nature of the class (except that two of these objects can be compared by means of compareTo()).

The protocol is a description of:

  1. the messages that are understood by the object,
  2. the arguments that these messages may be supplied with, and
  3. the types of results that these messages return.
  4. the invariants that are preserved despite modifications to the state of the object
  5. the exceptional situations that will be required to be handled by clients to the object

If the objects are fully encapsulated then the protocol will describe the only way in which objects may be accessed by other objects.

Some programming languages directly support protocols or interfaces (Objective-C, Java, C#, D, Ada). Older languages may also have features that can support the interface concept, such as abstract base classes with pure virtual functions in C++, or object-oriented features in Perl.

Note that functional programming and distributed programming languages have a concept which is also called a protocol, but whose meaning is subtly different (i.e. a specification of allowed exchanges of messages, emphasis on exchanges, not on messages). This difference is due to somewhat different assumptions of functional programming and object-oriented programming paradigms. In particular, the following are also considered as part of a protocol in these languages:

  1. The allowed sequences of messages
  2. Restrictions placed on either participant in the communication
  3. Expected effects that will occur as the message is handled

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.