Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Interface (computing)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== In object-oriented languages === {{Main article|Interface (object-oriented programming)|Concept (generic programming)}} In some [[object-oriented]] languages, especially those without full [[multiple inheritance]], the term ''interface'' is used to define an [[Abstract data type|abstract type]] that acts as an [[abstraction]] of a [[Class (computer science)|class]]. It contains no data, but defines behaviours as [[Method (computer science)|method]] signatures. A [[class (computer science)|class]] having code and data for all the methods corresponding to that interface and declaring so is said to ''implement'' that interface.<ref>{{cite web|url=http://docs.oracle.com/javase/tutorial/java/concepts/interface.html|title=What Is an Interface|work=The Java Tutorials|publisher=Oracle|access-date=2012-05-01|url-status=live|archive-url=https://web.archive.org/web/20120412093619/http://docs.oracle.com/javase/tutorial/java/concepts/interface.html|archive-date=2012-04-12}}</ref> Furthermore, even in single-inheritance-languages, one can implement multiple interfaces, and hence can ''be'' of different types at the same time.<ref>{{cite web|url=http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html|title=Interfaces|work=The Java Tutorials|publisher=Oracle|access-date=2012-05-01|url-status=live|archive-url=https://web.archive.org/web/20120526080117/http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html|archive-date=2012-05-26}}</ref> An interface is thus a [[data type|type]] definition; anywhere an object can be exchanged (for example, in a [[function (computer science)|function]] or [[method (computer science)|method]] call) the ''type'' of the object to be exchanged can be defined in terms of one of its implemented ''interface''s or base-classes rather than specifying the specific [[Class (computer science)|class]]. This approach means that any class that implements that interface can be used.{{citation needed|date=June 2018}} For example, a [[Skeleton (computer programming)|dummy implementation]] may be used to allow development to progress before the final implementation is available. In another case, a [[Test-driven development#Fakes, mocks and integration tests|fake or mock]] implementation may be substituted during testing. Such [[Method stub|stub]] implementations are replaced by real code later in the development process. Usually, a method defined in an interface contains no code and thus cannot itself be called; it must be implemented by non-abstract code to be run when it is invoked.{{citation needed|date=June 2018}} An interface called "<code>[[Stack (data structure)|Stack]]</code>" might define two methods: <code>push()</code> and <code>pop()</code>. It can be implemented in different ways, for example, <code>FastStack</code> and <code>GenericStack</code>βthe first being fast, working with a data structure of fixed size, and the second using a data structure that can be resized, but at the cost of somewhat lower speed. Though interfaces can contain many methods, they may contain only one or even none at all. For example, the [[Java (programming language)|Java]] language defines the interface {{Java|Readable}} that has the single {{Java|read()}} method; various implementations are used for different purposes, including {{Java|BufferedReader}}, {{Java|FileReader}}, {{Java|InputStreamReader}}, {{Java|PipedReader}}, and {{Java|StringReader}}. [[Marker interface pattern|Marker interfaces]] like {{Java|Serializable}} contain no methods at all and serve to provide run-time information to generic processing using [[Reflection (computer programming)|Reflection]].<ref> {{cite web |access-date = 2011-08-04 |publisher = Precise Java |title = Performance improvement techniques in Serialization |quote = We will talk initially about Serializable interface. This is a marker interface and does not have any methods. |url = http://www.precisejava.com/javaperf/j2se/Serialization.htm |url-status = live |archive-url = https://web.archive.org/web/20110824150046/http://www.precisejava.com/javaperf/j2se/Serialization.htm |archive-date = 2011-08-24}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)