World Library  
Flag as Inappropriate
Email this Article

Interface (object-oriented programming)

Article Id: WHEBN0000079499
Reproduction Date:

Title: Interface (object-oriented programming)  
Author: World Heritage Encyclopedia
Language: English
Subject: Interface, Mixin, Java class file, Interface design (disambiguation), Dependency injection, List of software development philosophies, SharpEnviro, Object-oriented design
Collection:
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Interface (object-oriented programming)

Not to be confused with Interface (computing).

In object-oriented programming, a protocol or interface is a common means for unrelated objects to communicate with each other. These are definitions of methods and values which the objects agree upon in order to cooperate.[1]

For example, in Java (where protocols are termed interfaces), the Comparable interface specifies a method compareTo() which implementing classes should implement. 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.
  3. The types of results that these messages return.
  4. The invariants that are preserved despite modifications to the state of an 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 (Ada, C#, D, Dart, Delphi, Java, Logtalk, Object Pascal, Objective-C, PHP, Racket, Seed7). 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.

Although the Go programming language is not generally considered an object-oriented language, it does allow methods to be defined on user-defined types. Go has "interface" types that are compatible with any type that supports a given set of methods (the type does not need to explicitly implement the interface). The empty interface, interface{}, is compatible with all types.

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.

See also

References

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.