GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing en.wikipedia.org — Interface (object-oriented programming) - Wikipedia In object-oriented programming, an interface or protocol type [a] is a data type that acts as an abstraction of a class. It describes a set of method signatures, the implementations of which may be provided by multiple classes that are otherwise not necessarily related to each other.[1] A class which provides the methods listed in an interface is said to implement the interface,[1] or to adopt the protocol.[2] Interfaces are useful for encapsulation and reducing coupling. For example, in Java, the ExamplesSome programming languages provide explicit language support for interfaces: Ada, C#, D, Dart, Delphi, Go, Java, Logtalk, Object Pascal, Objective-C, OCaml, PHP, Racket, Swift, Python 3.8. In languages supporting multiple inheritance, such as C++, interfaces are abstract classes. In Java, an implementation of interfaces may look like: class Animal { ... } class Theropod extends Animal { ... } interface Flyable { void fly(); } interface Vocal { void vocalize(); } public class Bird extends Theropod implements Flyable, Vocal { // ... public void fly() { ... } public void vocalize() { ... } } In languages without explicit support, interfaces are often still present as conventions; this is known as duck typing. For example, in Python, any class can implement an Type classes in languages like Haskell, or module signatures in ML and OCaml, are used for many of the same things as are interfaces. In Rust, interfaces are called traits.[4] In Rust, a trait Pet { fn speak(&self); } struct Dog { // Structs only contain their fields name: String } impl Dog { // Not from a trait fn new(name: String) -> Self { Dog { name } } } impl Pet for Dog { // From a trait fn speak(&self) { println!("{} says 'Woof!'", self.name); } } fn main() { let dog = Dog::new(String::from("Arlo")); dog.speak(); } In C++, there are multiple ways to resemble interfaces. One such way is the Java-style interface, which is done using abstract classes. The other, which resembles Go interfaces, is using concepts. Unlike inheritance, with concepts any type may satisfy a concept (not just classes) so long as it satisfies all of its requirements. See alsoNotes
References
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |