Interface (computing) explained

In computing, an interface is a shared boundary across which two or more separate components of a computer system exchange information. The exchange can be between software, computer hardware, peripheral devices, humans, and combinations of these.[1] Some computer hardware devices, such as a touchscreen, can both send and receive data through the interface, while others such as a mouse or microphone may only provide an interface to send data to a given system.[2]

Hardware interfaces

See main article: article and Hardware interface. Hardware interfaces exist in many components, such as the various buses, storage devices, other I/O devices, etc. A hardware interface is described by the mechanical, electrical, and logical signals at the interface and the protocol for sequencing them (sometimes called signaling).[3] A standard interface, such as SCSI, decouples the design and introduction of computing hardware, such as I/O devices, from the design and introduction of other components of a computing system, thereby allowing users and manufacturers great flexibility in the implementation of computing systems. Hardware interfaces can be parallel with several electrical connections carrying parts of the data simultaneously or serial where data are sent one bit at a time.[4]

Software interfaces

See also: Application binary interface and Application programming interface.

A software interface may refer to a wide range of different types of interfaces at different "levels". For example, an operating system may interface with pieces of hardware. Applications or programs running on the operating system may need to interact via data streams, filters, and pipelines.[5] In object oriented programs, objects within an application may need to interact via methods.[6]

In practice

A key principle of design is to prohibit access to all resources by default, allowing access only through well-defined entry points, i.e., interfaces.[7] Software interfaces provide access to computer resources (such as memory, CPU, storage, etc.) of the underlying computer system; direct access (i.e., not through well-designed interfaces) to such resources by software can have major ramifications—sometimes disastrous ones—for functionality and stability.

Interfaces between software components can provide constants, data types, types of procedures, exception specifications, and method signatures. Sometimes, public variables are also defined as part of an interface.[8]

The interface of a software module A is deliberately defined separately from the implementation of that module. The latter contains the actual code of the procedures and methods described in the interface, as well as other "private" variables, procedures, etc. Another software module B, for example the client to A, that interacts with A is forced to do so only through the published interface. One practical advantage of this arrangement is that replacing the implementation of A with another implementation of the same interface should not cause B to fail—how A internally meets the requirements of the interface is not relevant to B, which is only concerned with the specifications of the interface. (See also Liskov substitution principle.)

In object-oriented languages

See main article: article, Interface (object-oriented programming) and Concept (generic programming). In some object-oriented languages, especially those without full multiple inheritance, the term interface is used to define an abstract type that acts as an abstraction of a class. It contains no data, but defines behaviours as method signatures. A class having code and data for all the methods corresponding to that interface and declaring so is said to implement that interface.[9] Furthermore, even in single-inheritance-languages, one can implement multiple interfaces, and hence can be of different types at the same time.[10]

An interface is thus a type definition; anywhere an object can be exchanged (for example, in a function or method call) the type of the object to be exchanged can be defined in terms of one of its implemented interfaces or base-classes rather than specifying the specific class. This approach means that any class that implements that interface can be used. For example, a dummy implementation may be used to allow development to progress before the final implementation is available. In another case, a fake or mock implementation may be substituted during testing. Such 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. An interface called "[[Stack (data structure)|Stack]]" might define two methods: push and pop. It can be implemented in different ways, for example, FastStack and GenericStack—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 language defines the interface that has the single method; various implementations are used for different purposes, including,,,, and . Marker interfaces like contain no methods at all and serve to provide run-time information to generic processing using Reflection.[11]

Programming to the interface

The use of interfaces allows for a programming style called programming to the interface. The idea behind this approach is to base programming logic on the interfaces of the objects used, rather than on internal implementation details. Programming to the interface reduces dependency on implementation specifics and makes code more reusable.[12]

Pushing this idea to the extreme, inversion of control leaves the context to inject the code with the specific implementations of the interface that will be used to perform the work.

User interfaces

See main article: article and User interface.

A user interface is a point of interaction between a computer and humans; it includes any number of modalities of interaction (such as graphics, sound, position, movement, etc.) where data is transferred between the user and the computer system.

See also

Notes and References

  1. Book: Interface . Chapter 1: The Subject of the Interface . Hookway, B. . MIT Press . 1–58 . 2014 . 9780262525503.
  2. Encyclopedia: 2000 . IEEE 100 - The Authoritative Dictionary Of IEEE Standards Terms . IEEE Press . NYC, NY, USA . 9780738126012 . 574–575.
  3. See also:
  4. Book: https://books.google.com/books?id=Hyl8SA1eHzIC&pg=PA142 . 3.15 Peripheral Interfaces and Controllers - OG . IBM PC And Clones: Hardware, Troubleshooting And Maintenance . Govindarajalu, B. . Tata McGraw-Hill Publishing Co. Ltd . 142–144 . 2008 . 9780070483118 . 15 June 2018.
  5. Book: Mastering Cloud Computing . Buyya, R. . Tata McGraw-Hill Education . 2.13 . 2013 . 9781259029950.
  6. Book: Chapter 2: Object, Class, Message and Method . Object-Oriented Programming and Java . Poo, D. . Kiong, D. . Ashok, S. . Springer-Verlag . 7–15 . 2008 . 9781846289637.
  7. Web site: 2011-08-03 . Bill Venners . 2005-06-06 . artima developer . Leading-Edge Java: Design Principles from Design Patterns: Program to an interface, not an implementation - A Conversation with Erich Gamma, Part III . Once you depend on interfaces only, you're decoupled from the implementation. That means the implementation can vary, and that is a healthy dependency relationship. For example, for testing purposes you can replace a heavy database implementation with a lighter-weight mock implementation. Fortunately, with today's refactoring support you no longer have to come up with an interface up front. You can distill an interface from a concrete class once you have the full insights into a problem. The intended interface is just one 'extract interface' refactoring away. ... . live . https://web.archive.org/web/20110805191904/http://www.artima.com/lejava/articles/designprinciples.html . 2011-08-05.
  8. Book: Computer Organization and Design: The Hardware/Software Interface . Patterson, D.A. . Hennessy, J.L. . 7 August 2004 . Elsevier . 3rd . 656 . 9780080502571.
  9. Web site: What Is an Interface. The Java Tutorials. Oracle. 2012-05-01. live. https://web.archive.org/web/20120412093619/http://docs.oracle.com/javase/tutorial/java/concepts/interface.html. 2012-04-12.
  10. Web site: Interfaces. The Java Tutorials. Oracle. 2012-05-01. live. https://web.archive.org/web/20120526080117/http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html. 2012-05-26.
  11. Web site: 2011-08-04 . Precise Java . Performance improvement techniques in Serialization . We will talk initially about Serializable interface. This is a marker interface and does not have any methods. . live . https://web.archive.org/web/20110824150046/http://www.precisejava.com/javaperf/j2se/Serialization.htm . 2011-08-24.
  12. Book: Gamma . Helm . Johnson . Vlissides . 1995 . Design Patterns: Elements of Reusable Object-Oriented Software . registration . Addison Wesley . 17–18. 9780201633610 .