Protocol (object-oriented programming)

Protocol (object-oriented programming)

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:
# the messages that are understood by the object,
# the arguments that these messages may be supplied with, and
# the types of results that these messages return.
# the invariants that are preserved despite modifications to the state of the object
# 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, Logtalk). 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:

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

ee also

* Class
* Encapsulation
* Public interface
* Private interface
* List of basic computer science topics
* Application programming interface


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Object-oriented programming — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computing …   Wikipedia

  • Object-Oriented Programming in Common Lisp: A Programmer's Guide to CLOS — (1988, Addison Wesley, ISBN 0 201 17589 4) is a book by Sonya Keene on the Common Lisp Object System. Published first in 1988, the book starts out with the elements of CLOS and develops through the concepts of data abstraction with classes and… …   Wikipedia

  • Comparison of programming languages (object-oriented programming) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • List of object-oriented programming terms — Those words found in object oriented programming. Some are related to OOP and some not. A * Abstract class (also called deferred class) * Abstract method * Abstraction (computer science) * Access control * Accessor method * Allocated class *… …   Wikipedia

  • Service Oriented Programming — (SOP) is a programming paradigm that uses services as the unit of computer work, to design and implement integrated business applications and mission critical software programs. Services can represent steps of business processes and thus one of… …   Wikipedia

  • Protocol — may also refer to:Standards in information automation: * Communications protocol * Protocol (computing) * Protocol (object oriented programming) * Cryptographic protocolProcedures for human behavior: * Protocol (diplomacy) * Protocol, a.k.a.… …   Wikipedia

  • Object (computer science) — In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure. (With the later introduction of object oriented programming the same word,… …   Wikipedia

  • Object copy — An object copy is an action in computing where a data object has its attributes copied to another object of the same data type. An object is a composite data type in object oriented programming languages. The copying of data is one of the most… …   Wikipedia

  • Protocol (computing) — In computing, a protocol is a convention or standard that controls or enables the connection, communication, and data transfer between two computing endpoints. In its simplest form, a protocol can be defined as the rules governing the syntax,… …   Wikipedia

  • Comparison of programming languages (mapping) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”