Talk:Interface (object-oriented programming)

WikiProject iconComputing Start‑class High‑importance
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
 High This article has been rated as High-importance on the project's importance scale.

Disputed sense of protocol Edit

The term protocol in object-oriented programming means more than just the signatures of the methods owned by a given class. The protocols of a class include how that class expects to be used, viz. the order in which methods expect to be invoked. This is now recognised, for example, in UML 2.x statecharts, where the term protocol machine is used to describe the state machine of a class, representing legal sequences of method invocations. This behavioural use of protocol goes back to Smalltalk days (although in some contexts, the weaker sense below was intended).

In the mid-1980s, the programming language Objective C introduced the term protocol as a syntactic term to denote an abstract interface, containing method signatures only, defined independently of the single-inheritance class hierarchy. This usage is more or less synonymous with the syntactic construct interface in Java, and was invented for a similar reason (viz. the desire to support only single inheritance, for convenience of implementation, but still allow multiple classification).

So, I would like to argue that the neutral definition of protocol should refer to the deeper, behavioural sense; and the Objective C usage (which is a specific syntactic term in the language) be moved to a page that discusses object-oriented interfaces in a neutral way, which subsumes interface (Java) and protocol (Objective C); and possibly also concept (C++ standard template library). AJHSimons (talk) 15:51, 18 February 2008 (UTC)Reply[reply]

Exactly what I perceived about "protocol"! Protocol should be about the behaviour, about the (abstract) state of the system/object. In particular, it should tell the user/client how to use the object, in what order the methods must be called, not just what methods the object provides. Lê Harusada (talk) 03:45, 30 October 2011 (UTC)Reply[reply]
I think the historical "weak" sense of "protocol" used by Objective-C and implicitly by SmallTalk was due to the overstatement of the method invocation as "messaging between objects". Thus, the Java's interface simply defines the messaging protocol between objects, even though partially. Hence, I think the good old SmallTalk and Objective-C should be mentioned in the article instead of the mordern Java! Lê Harusada (talk) 05:35, 30 October 2011 (UTC)Reply[reply]
Support. A "protocol" requires a description of the behavior, of the states at both sides and not merely of messages. The proper term here - IMO - is "interface" / "abstract interface" - to show that the formal specification of (abstract) methods does not qualify for a "protocol", but is only a part of what is possibly a specification of a communication protocol. AFAIK, it has always been "separating interface and implementation", not "separating protocol and implementation". To use "protocol" here is confusing and misleading. (talk) 14:47, 17 March 2014 (UTC)Reply[reply]

Merge with interface (Java) Edit

Regarding merging it with Protocol_(object oriented programming)... This article is fine the way it is. I was searching it, and found it in one go without having to dig through protocol --> object oriented --> java --> interfaces. 04:46, 20 February 2007 (UTC)Reply[reply]

The Interface is a Java term, not necessarily an object oriented programming term. Other languages use other terminology for similar technologies. This entry might reference the OOP protocol entries but should remain separate. Dblatt 13:21, 18 April 2007 (UTC)Reply[reply]

I agree with the above opinions. I had no idea what a Java Interface was, nor that it was related to OOP Protocol. I searched for it and found it easily this way.-- 20:15, 3 May 2007 (UTC)Reply[reply]

Due to the fact that this article is flagged to be 'wikified', I believe that merging this with Interface (Java) would only serve to degrade the quality of that article. Ph0t0phobic 23:13, 1 June 2007 (UTC)Reply[reply]

I am not saying that the Interface (Java) article is bad, but there just is no place for it.
The Java term "interface", which is also adopted by many other OOP languages, is equivalent to "protocol" as defined by this article; indeed, the lead section even lists it as a synonym. Given that the functionality of interfaces in all the Java-derived languages is the same as the one described by this article, there is no reason we should have this article and a separate Java-specific one separately. Having two articles on the exact same topic can only serve to fragment Wikipedia and duplicate effort.
The merge needn't degrade the quality of either article: the whole point of merging is to choose the good and throw away the bad. I am hereby re-introducing the merge tags. -- intgr #%@! 07:39, 28 August 2007 (UTC)Reply[reply]

I agree with the opinions to keep this page seperate. The fact that it is a Java specific topic is the ultimate reason why I think it should remain seperate. The Protocol page should remain generalized and should have no specific indication of language dependancy, except for maybe in examples, in which case appropriate comments should be made. Alex 18:41, 28 September 2007 (UTC)Reply[reply]

How are interfaces Java-specific? So I suppose we should write interface (C++), interface (C sharp), interface (Object Pascal), etc too? And well interfaces is hardly the only feature of programming languages, why why not array (Java), array (C++), array (Pascal), array (Perl), array (Python) ad nauseam. Because this is exactly what you're proposing here!
Interfaces in Java are not special, the article is just an unnecessary content fork. -- intgr [talk] 12:30, 29 September 2007 (UTC)Reply[reply]

Merge with concepts in C++ STL Edit

No point in having separate articles for each language - one thinks of C# interfaces, and C++ concepts that will become standard in 2009 (see Concept (generic programming) and C++0x#Concept). Well, same thing; this article should explain the general idea and give a couple of examples to illustrate its implementation in each major language (and not to serve as a comprehensive programming guide). That is: Interface (Java) should be pruned a bit and merged from. GregorB 22:14, 3 October 2007 (UTC)Reply[reply]
Yes, and everything that's left of Interface (Java) after "pruning a bit and merging from" would be simply a tutorial, and should be deleted anyway (WP:NOT#Wikipedia is not a manual, guidebook, or textbook). That's what a merge is. -- intgr [talk] 21:01, 7 October 2007 (UTC)Reply[reply]

Java interfaces are completely related to interfaces in other languages and C++ pure virtual functions and all fall back into the definition given in this article, and should be merged.

That being said, C++ concepts are not quite the same. Concepts in C++ will define a set of requisites for a given metaprogramming template, that is in a different level than Java interfaces, C# interfaces or C++ pure virtual methods. The latter define an specific message, while the former does not require the existence of a message. A C++ concept may define that there is a + operator that applies to class A and class B, but it does not require an A& operator+( const B& ) method in A class definition, the same functionality can be expressed in any other way, like an out of class A operator: A& operator+( A&, const B& ), thus a concept may not require a definition of a message between two classes (as the latter operator is not even part of any class). While the example may seem quite subtle, C++ concepts can define non-message requirements like the existence of an internal type definition in the class. (From C++0x#Concept):

concept InputIterator<typename Iter>
  typename value_type;
  typename reference;
  typename pointer;
  typename difference_type;
  // ...
that requirement is not a message definition of any kind, but a helper for metaprogramming. I don't believe that this article and Concept (generic programming) should be merged. —Preceding unsigned comment added by (talk) 20:25, 31 October 2007 (UTC)Reply[reply]
If I understand correctly, protocol would be more or less synonymous with interface, but not with concept, which, in fact, subsumes protocol because it also defines internal organization of a class, not just its outward appearance. This would indeed be a substantial difference, so I think you have a good point here. GregorB (talk) 13:14, 22 November 2007 (UTC)Reply[reply]
Also, in your previous example, an int could be class A and a double could be class B, even though int doesn't have any explicit operator+ (it's built into the compiler), and int wouldn't be explicitly "implementing the addable-with-B interface". I believe that's another important difference with interfaces. (talk) 03:10, 1 June 2008 (UTC)Reply[reply]

I think interface is the more common term Edit

When a programmer says ‘interface’ they almost always mean this unless explicitly prefixed by ‘user’. But when he says ‘protocol’ he'll be talking about http and such. Shinobu (talk) 18:57, 6 September 2008 (UTC)Reply[reply]

I think this is incorrect. Programmers usually use the term "interface" in the sense it is used in the phrase "program to interfaces, not implementations" from the Gang of Four's Design Patterns book. Erich Gamma, one of members of the Gang of Four, makes it clear that "interfaces" in this context means APIs, not protocols. See for example the second paragraph of his response to the second question of the interview at The distinction between protocols and APIs is sometimes lost to Java programmers because protocols are the most natural way to separate implementation from interface in Java, and because Java uses the term "interface" to refer to protocols. In other languages (at least Objective-C, I'm less familiar with C++ and C#), a separate header file is typically used instead of protocols to separate interface from implementation. The confusion Java fosters between "interfaces" in the usual (Gang of Four) sense and "interfaces" in the Java sense (i.e. "protocols") makes it all the more important for this article to retain the term "protocol" as to be separate from any Java-specific "interface" article. — Preceding unsigned comment added by 2620:0:1000:1B01:992C:E1EB:357A:B769 (talk) 22:33, 7 June 2012 (UTC)Reply[reply]

Victim of Misunderstanding Edit

This page is clearly the victim of merging by people who are not knowledgeable in the field. A protocol is not the same as an interface. At best an interface might be an element of a protocol. Interface is a common term among computer programmers which denotes a set of method signatures with no included implementation. It has a very clear concrete meaning which is distinct from that of a protocol, which is much more broad. While they might server similar purposes, ie that of abstraction and creation of a contract for the purpose of communication, they are very different animals. They are different in about the same way that a bicycle is different from a freeway. Waylonflinn (talk) 23:04, 7 October 2011 (UTC)Reply[reply]

I strongly agree. A protocol is a sequence of messages or actions by which something is negotiated or performed: for example, TCP/IP is a protocol. (You might use a UML sequence or activity diagram for it.) An interface in the Java sense is just a collection of method signatures. (You might use UML class diagram for it.) Protocol is a comms term.Rick Jelliffe (talk) 09:39, 2 April 2018 (UTC)Reply[reply]

This article is meant to be about the object-oriented concept of protocols, no communication protocols. The former are named in analogy to the later but exist independently and are significantly different. I think the Waylonflinn comment you were replying to is a reference to the fact that people are editing this article without a full understanding of the different between object-oriented protocols and interfaces, not a claim that interfaces aren't protocols because they're not communication protocols, even though they indeed are not that either :-). TFJ76 (talk) 11:33, 11 November 2022 (UTC)Reply[reply]

Only some languages Edit

Oh, I think I see the problem. This page claims that protocol is a specialist name for a kind of interface used in Object Oriented Programming. However, it seems that only a few OOLs uses this term: Objective C, Swift etc. Hence the mystification that programmers from other languages are registering. (Is there any other language that might prove that it is a general term?) Rick Jelliffe (talk) 09:50, 2 April 2018 (UTC)Reply[reply]

I have bitten the bullet, and rearranged the article:

  • All the non-OO material is put under a separate heading. Why is it even there?
  • I have rewritten the top sectiont to say that protocol used in a variety of specialist senses, as well as its more general sense. And added the examples of this: objective-c, swift, clojure, elixir

However, what is still perhaps missing is details that each of those languages mean something different by protocol. In clojure, it means a kind of dynamic dependency injection, my superficial research is that in objective C is an interface, in elixir it is dynamic dispatch, and in swift it seem more interface/traits/mixins.

So I hope my edits sort out the controversy better, and allow more improvements without arguments on words.Rick Jelliffe (talk) 11:06, 2 April 2018 (UTC)Reply[reply]

I'm afraid this edit, valiant as it was, might do more harm than good. A protocol is an object-oriented programming concept that is known by the term "protocol" in some programming languages, notably in Smalltalk where I think it originated, by the term "interface" is some other programming languages, and by other terms elsewhere (though not "Trait", that's a somewhat related but different concept). Only some programming languages directly support protocols (or its "interface" equivalents) but it's a concept totally independent of any programming language and that could potentially be implemented in a program using almost any language. Thus starting the article with the statement "Protocol is a term" is both incorrect and confusing. This confusion is evident in the rest of the article after your edits, and to some extent even in your talk post above, because once the article sets out to document "protocol" as a term in some programming languages then the subtle distinction between the uses of that term in different languages or the use of different terms in different languages for similar concepts dominates, when these interesting but peripheral topics should be addressed but should neither form the bulk or the article not find their way into its leading sentence. WP:NOTGUIDE might require that, but mostly I think presenting things this way buries under implementation details the real value of this article, an explanation of the concept of "protocol", by whatever name, term, or keyword that concept is known.
As I think this talk page shows, a proper explanation of protocols is rendered difficult by the fact that many programmers have not been exposed to protocols as a clear concept distinct from any implementation (see Victim of Misunderstanding above). Many are coming to this article from Java's interfaces, which can be used to implement protocols but also programming interfaces, hence the corresponding keyword and concept's name in Java. That Java concept of "Interfaces" is significantly different from the general object-oriented programming concept of "Protocols", even though the former is used to implement the later in Java, and that is confusing to many. This confusion is all the more reason to have this article focus on the concept and not get lost in naming and implementation details.
A good model is the article Constant_(computer_programming). Like "Protocol", "Constant" is a programming concept independent of programming languages. In some languages it's implemented using the keyword "constant" or "const", while the keyword "final" is used in some other languages (notably Java), and still other keywords or implementation mechanisms are used in other languages. But the article Constant_(computer_programming) focuses first on the concept known by the name "constant" and not on the term "constant" and its variations, and it discusses particular language names and implementations only after the concept is well explained.
The confusion resulting from treating "protocol" as a term rather than a concept will exist regardless of whether that concept ends up getting called "protocol", "interface", or anything else in this article. I think there are some good reasons to prefer the term "protocol" (it's as far as I know the original term used for that concept, it avoids confusion with programming interfaces, and it provides a good analogy to communication protocols), but that's a topic for another section of this talk page (and by the look of it, most sections of this talk page :-).
I think a further edit is needed. Ideally this edit would cite references for both the origin of the concept and the history of the different terms it's associated with. Ideally also I would have the time and ability to do this myself but that's not the case right now :-). Thanks for your edits and hopefully it will advance the article towards an even better final form. TFJ76 (talk) 11:18, 11 November 2022 (UTC)Reply[reply]
(Legitimately trying to understand; I hope my repeated replies everywhere don't come off as argumentative.)
That Java concept of "Interfaces" is significantly different from the general object-oriented programming concept of "Protocols"
I think a lot of what we (people who know the concept from the Java-like family of languages) are stuck on is that we don't see how it's significantly different, while everyone here claiming that seems to think it's self-evident. As a result, we're all just yelling "it's obviously different!" and "it's obviously the same thing!" at each other.
Can you explain the difference, for a hypothetical programmer who has only ever used Java, has a severe case of the blub paradox, and has never seen this page before? mi1yT·C 14:08, 14 November 2022 (UTC)Reply[reply]
Thank you 3mi1y, your comments are very thoughtful, often insightful, as are Wpscatter's, and your references very relevant. Apologies for not answering earlier, I've been busy, but let me try to answer your specific question here.
The problem is that "interface" has two meanings in Java: The first, which I'll call interface(Interface), is the general programming interfaces one, made famous by the phrase "Program to an interface, not an implementation". The second, which I'll call interface(Protocol), is what Objective-C and some other languages call a protocol, and I think we'd agree that concept should be the subject of this article. Here are how these two meanings exist in Java in my understanding of the language:
  1. Unlike Objective-C and its @interface keyword, Java, like Swift, does not have a specific language construct for interfaces(Interface). Java programmers let API users derive a classe's interface(Interface) from its implementation code, or use Javadoc to communicate it, or use the interface keyword to create an interface(Protocol) adopted by just that one class (which would be an anti-pattern in Objective-C for example). Even without a language construct this concept of interface(Interface) exist in Java simply because it exist in pretty much every software system.
  2. Java and a number of other languages uses the interface keyword to implement interfaces(Protocol), and this can lead to two types of confusion: (a) The surprise of people unfamiliar with the term "protocol" finding their familiar interfaces(Protocol) concept called by that foreign name, as very evident in this talk page; and (b) People using the term "interface" in contexts where it is not clear whether they mean interface(Interface) or interface(Protocol). One example of the later is this otherwise very good blog post explaining the concept of "programming to an interface". Another one is this article proposing a way to implement interfaces(Protocol) in Python, totally unaware that Python had already implemented this in its Protocol class :-). That article is particularly illustrative of the confusion because one can't read its first sentence ("Interfaces play an important role in software engineering") without thinking the article is going to be about interfaces(Interface). It's not until the third sentence when one can start to understand it might be talking about interfaces(Protocol), and even that requires a good understanding of interfaces(Protocol) and the distinction between the two meanings of "interface". A glaring example of this (b) confusion is in Wikipedia's Interface (computing) article, which states that for some object-oriented languages "interface" means interface(Protocol). This is ridiculous because "Program to an interface, not an implementation" doesn't suddenly mean "Program to an interface(Protocol), not an implementation" when you're programming in Java while it means "Program to an interface(Interface), not an implementation" in C :-).
So the answer to your question depends on whether "the java concept of 'interfaces'" you ask about refers to interface(Protocol), which I think is your intent, or a combination of interface(Protocol) and interface(Interface), which is what I meant in my first use of that phrase, or something else. If you indeed meant the former then there is no obvious difference (beyond some implementation details) between that concept and the one called "protocol" by languages that used that term. There are however subtle but significant differences in practice that might involve the blub paradox you refer to: In a number of years programming in Java as well as Objective-C I've found a perceptible difference between programmers who know about interfaces(Protocol) only by the term "interface" and those who also know them as "protocols". The later tend to use interfaces(Protocol) more often as first-class types in their API designs, rather than simply as a type of class-less interfaces(Interface) (as in "I have this class Foo, but I want people to use it in contexts where they can't put their object in the right place in the class hierarchy, for example to create mocks for testing, so I'll just create an IFoo interface for my Foo class to implement"). The more powerful use of interfaces(Protocol) as first class types tend to lead to simpler and more eloquent APIs, sometimes very notably so, and this is possibly the impetus for the recent "protocol-oriented programming" movement (which I also think of as somewhat of a buzzword, since using interfaces(Protocol) effectively is not a new type of programming but core to good object-oriented programming).
There are individual differences of course and I'm not saying programmers using one language always do better or worse object-oriented design than ones using the other. Also, the differences I've experienced may not be due primarily to the language term used: Many people who learned about interfaces(Protocol) as "protocols" did so in the context of NeXTSTEP, Mac OS X, and iOS and their AppKit, Cocoa, and Cocoa Touch frameworks. These frameworks are really great examples of the effective use of interfaces(Protocol) to simplify API (downright beautifully so in my opinion). Unfortunately understanding this use takes more than just reading the documentation for interfaces(Protocol) in Swift or Objective-C. The best introduction to the good use of interfaces(Protocol) that I know of is Stanford's CS193p class, a class created by the person who led the development of NextStep's AppKit. A goal for this Wikipedia article might be to communicate as much as possible about that type of good use of interfaces(Protocol)... without requiring people to take a semester's worth of a college class :-).
Because of the benefits of interfaces(Protocol) when they're understood as full types rather than just specialized interfaces(Interface), and to try to avoid confusion (b) above, I would oppose renaming this article to "Interface (object-oriented_programming)", and I think that's also why most people who've come to learn interfaces(Protocol) through the "protocol" term also oppose it. I recognize however that if we don't rename this articles we still a need to reduce confusion (a) above. Perhaps this could be achieved with an introduction similar to the following:
In object-oriented programming a protocol is a type that is defined by the characteristics of objects instead of by the position of those objects in a class hierarchy. Some languages (Java, C#, Go, ...) use the term "interface" to refer to these types, while other languages (Python, Swift, Objective-C, Clojure, Smalltalk, ...) use the term "protocol" and reserve the term "interface" for the more general concept of programming interfaces, and in some cases (Objective-C) for languages constructs specifically designed to support that concept.
The rest of the article would need a significant refactor to reduce the interface/protocol confusion (like removing the frequent references to communication protocols) and increase the amount of information about interfaces(Protocol) beyond the fact that they're usually a set of methods/functions and variables/properties. I'd imagine that after the introductory section with an explanation a bit more detailed than the one suggested above there could be a section about history that would include whatever origin story we can find (I think Smalltalk but I'm not sure) and also a timeline of when the concept was added to other languages, with the general mechanism used for each, then a section of examples in different languages (certainly Java and probably Swift, though Python might be good too, it's currently one of the most popular programming language and its implementation of interface(Protocol) is uber-cool, they managed to bring duck-typing to it—or vice-versa), then examples of design patterns using protocoles, like delegation, then perhaps a discussion of some more advanced interface(Protocol) features available in certain languages. TFJ76 (talk) 09:28, 15 November 2022 (UTC)Reply[reply]
Ugh. Okay, new plan. We make up two entirely new distinct words for these two things, publish a bunch of stuff using them, and then come back here in a decade after they catch on and fix this nonsense. We're programmers, we shouldn't have to deal with this level of imprecision.
Serious response:
  • To use your terms, yes, the thing I am referring to when I say "Java/C# style interfaces" is an interface(protocol). We do agree after all that those are essentially the same thing, so that's one point of confusion solved.
  • The Java/C# interface(interface) would just be... a class's public methods, I guess? I don't think I've ever actually needed a specific word to refer to that, and I can't convince Google to give me a page saying so because it thinks I want interface(protocol)s, but if someone started talking about "the interface of this class, but not like a declared interface with the interface keyword, just the way you use it from outside the class" I would understand this as "the public methods of the class".
  • I have definitely seen both of these styles of interface(protocol) usage in C# (which I actually have way more experience with than Java, but also I know its concept of interface(protocol)s is taken from Java so I keep saying that instead). I agree with your ideas on good use of interface(protocol)s, and don't see them as particularly revolutionary; possibilities here are (1) I've worked mostly with better-than-average developers, (2) C# people get it right more often than Java people do and I've forgotten how bad it is in Java, or (3) I'm blub-paradoxing myself, having never used any of the Apple stuff :) Regardless, this part isn't particularly relevant.
  • I'm not sure where this leaves us. Having the article named "protocol" seems very weird and wrong to me, in much the same way as if you was named tu instead (Latin was here before modern English, you see, and lots of people still use languages where "tu" is still a word). But you and nearly half the rest of the world feel equally strongly in the other direction.
Given that, I think for now I'm going to close my rename proposal as no-consensus, and try to rewrite this and the other n language-specific content forks into a form where it's less of an issue. mi1yT·C 10:56, 15 November 2022 (UTC)Reply[reply]
To make this even more confusing I just found out that Java's own tutorial define its interfaces as what I would call interface(Interface) in, specifically "Methods form the object's interface with the outside world", with no mention of the ability to use interfaces to implement polymorphism. If I understand that way of seeing things correctly Java interfaces are interfaces(Interface) and the fact that they can be used to implement interfaces(Protocol) is a programming technique, a natural consequence of the language's support for interfaces(Interface).
This makes sense, but poses a problem for languages like Swift or Python that don't have language support for interfaces(Interface) but do provide support for interfaces(Protocol), or for languages like Objective-C that support interfaces(Interface) but not in ways that can be used to implement interfaces(Protocol) (hence the existence of two different keywords in that language).
I'm still of the opinion that there are two concepts, the interface(Interface) one ("the public methods of the class" if you will, but also well defined by the "program to an interface, not to an implementation" phrase), and the interface(Protocol) one, and that Java supports both with its interface keyword and concept, and that both are necessary because the interface(Protocol) way of viewing the world is an important aspect of object-oriented programming and not just an implementation side affect of interfaces(Interface).
In lieu of us publishing a bunch of stuff using two new words for these two old concepts, I've reached out to some distant contacts in academia to see what papers or articles have been published specifically about the interface(Protocol) concept (there is already much published about the interface(Interface) concept, some of it documented in Interface (computing)).
In the meantime, and as time allows, I will start massaging this article into a form hopefully more understandable for all, independently of any renaming discussion. TFJ76 (talk) 12:23, 15 November 2022 (UTC)Reply[reply]
If it's of any interest to you, I'd say that the C# documentation on interfaces explains their role in Java/C# much better than the offical Java tutorial (from 2014) does. It explicitly states that 'An interface defines a contract'[1], mentions how types can inherit multiple interfaces, and also discusses how they can be used to implement polymorphism[2]. And if you want a particularly comprehensive overview of what they can/can't do, there's the 'interfaces' section of the C# specification.
And if I'm understanding your prior messages correctly, this Contract, defined by the interface, is the Interface(protocol)? As in along the lines of 'FooBar implements the IFoo and IBar interfaces(interface). IFoo defines a contract for the expected functionality of a 'Foo', and must be implemented by classes (like FooBar) that are supposed to be usable as a 'Foo' (thus usable via the IFoo logical Interface(protocol)). Same for IBar except for a 'Bar' instead of a 'Foo'.'?
(apologies if that's a stupid question, just trying to make sure I haven't completely misunderstood your explanation)
🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talkedits) 14:43, 15 November 2022 (UTC)Reply[reply]
Yes, that's right, interface(Protocol) is the contract one, as in your IFoo/IBar/FooBar example. However typically in that world of interfaces(Protocol) there would be no IFoo/Foo and IBar/Bar dichotomy: Foo and Bar would be the contracts snf there would be no need for IFoo or IBar. If you wanted to provide default implementation for the methods of Foo or Bar, some languages support that (Objective-C and Swift), but you typically wouldn't need to provide both a class and an interface(Protocol) for the same concept. I've never seen that in Objective-C, and from my reading I think it would probably also be uncommon in Swift, Smalltalk, or Python. TFJ76 (talk) 15:15, 15 November 2022 (UTC)Reply[reply]
Thanks for those clarifications :)
Anywho, reason for the IFoo/IBar was mostly due to code conventions where interface classes tend to be prefixed with an 'I' to distinguish them from any sort of concrete implementation of a class, and I'm a filthy casual interface-brain 😅.
Regarding the point about dichotomies, I can think of some relatively-common situations of classes and interface(Protocol)s for the same concept are necessary. For example, collections - C# has ISet<T>, defining the interface(Protocol) for the 'set' data structure, along with the HashSet<T> and SortedSet<T> concrete implementations of this 'set' interface(Protocol) - only differing in how they work under the hood - but both are able to be used via this common interface(Protocol) - along with any other non-standard specialized implementations of the 'set' interface(Protocol).
Also on a related note, there's a somewhat common example of an interface(Protocol) I can think of for which a single concrete implementation is undefinable - the Iterator pattern's 'Iterator' (and 'Iterable') interface(Protocol).
🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talkedits) 18:30, 15 November 2022 (UTC)Reply[reply]
In the meantime, and as time allows, I will start massaging this article into a form hopefully more understandable for all, independently of any renaming discussion.
I just made a first pass at doing this, focusing on purging all the stuff about similarly named but different things. It's not good, but it's hopefully no longer "literally the entire talk page is extreme confusion" levels of bad.
I will continue to poke at it; feel free to do the same. mi1yT·C 08:33, 16 November 2022 (UTC)Reply[reply]

Protocol? Edit

Never heard of Interfaces being called Protocols ever, must be only on a few select languages. (talk) 16:01, 8 October 2018 (UTC)Reply[reply]

Proposed merge of Interface (Java) into Protocol (object-oriented programming) Edit

The following discussion is closed. Please do not modify it. Subsequent comments should be made in a new section. A summary of the conclusions reached follows.
Consensus to improve, but no consensus to merge, with stale discussion for 8 months. Klbrain (talk) 10:45, 28 August 2023 (UTC)Reply[reply]

I do not think Java's interfaces are sufficiently special to deserve their own article.

n.b. in 2007 there was a discussion about doing this in the other direction, which a surprising (to me) number of people were against. 3mi1y (talk) 07:27, 7 November 2022 (UTC)Reply[reply]

Merge. The concept as implemented by Java is not meaningfully different from other OOP languages. A large portion of the Interface (Java) article seems inappropriate per WP:NOTGUIDE. (As it happens, I've never heard the term "protocol" used this way, but the article appears to be the correct target regardless.) WPscatter t/c 07:31, 7 November 2022 (UTC)Reply[reply]
"Interface" is also the term I'm familiar with, but I'm willing to believe that people who learned the concept through other languages know the same thing by a different name.
"Interface" is probably the most common these days if only because of the sheer popularity of Java. 3mi1y (talk) 07:37, 7 November 2022 (UTC)Reply[reply]
Probably, yeah. I'd have to look into it but I might even support moving this page to Interface (object-oriented programming), but that's another discussion altogether :) WPscatter t/c 07:39, 7 November 2022 (UTC)Reply[reply]
glances up at the rest of this talk page
This might be the most controversial thing I ever propose here, but here we go... 3mi1y (talk) 07:47, 7 November 2022 (UTC)Reply[reply]
Oppose with comment. As per this reply of mine on the 'Requested move' thread, perhaps it might be best to rework Interface (Java) into a more general 'Interface type' article, keeping this article about whatever a 'Protocol' actually is (again, still not entirely sure what the concept of a 'protocol' is supposed to be, but the article is starting to give me the vibe that a 'protocol' is 'the way in which classes are designed to communicate with each other (often through the medium of interface types)', rather than 'a different name for interface types').
Additionally, making it an 'Interface type' article would directly address the notability issue, as, whilst Java's interfaces by themselves aren't that notable, an article containing a brief discussion of interface types, and how this functionality is present in multiple languages, would be a bit more justifiable (a la Enumerated type, Function type, Abstract type, etc). 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talkedits) 13:00, 14 November 2022 (UTC)Reply[reply]
I actually kind of like this. It's roughly equivalent, while sidestepping the whole "what even is a protocol" thing that we're all stuck on.
If we go this route, I might AfD this one later, unless someone comes along who can explain the difference in more than just "vibes" (because, while I get approximately the opposite vibes from you, they are still just vibes). That can be a problem for future-us, though. mi1yT·C 13:27, 14 November 2022 (UTC)Reply[reply]
Well, I've mentioned the 'Rework the Java interface article to make it not Java-only' idea on Talk:Interface (Java) (haven't formally proposed moving that article/starting the rework of it just yet), seeing as that idea involves changing that article.
However, upon reading some of the other threads on this talk page (especially considering @TFJ76's very recent clarifications on a couple of the older threads), it looks like this article probably isn't AfD-worthy, just in need of a hefty rewrite to make it say a bit more clearly what a protocol is, removing the tangents trying to explain interfaces. 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talkedits) 13:54, 14 November 2022 (UTC)Reply[reply]
Oppose. I think Java is important enough to deserve its own article for a Java interface. After all it has its own article for Java packages for namespaces, which -- theoretically -- could be included in a more general article as well. (talk) 08:42, 16 November 2022 (UTC)Reply[reply]
Respectfully I don't think this logic is sound. Sure, Java itself is important, but its use of interfaces is not meaningfully different from the norm. Should we have separate articles for Java classes, C++ classes, Python classes, etc? WPscatter t/c 16:57, 16 November 2022 (UTC)Reply[reply]
Not necessarily, but I wouldn’t mind. (talk) 10:20, 18 November 2022 (UTC)Reply[reply]
The discussion above is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.

Requested move 7 November 2022 Edit

The following discussion is an archived discussion of a requested move. Please do not modify it. Subsequent comments should be made in a new section on the talk page. No further edits should be made to this section.

Moved as proposed. After much-extended time for discussion, there is a narrow but actionabl consensus for a move. Some opposition to moving the article is based on difficulty parsing what the article intends to cover, but that is a separate issue from the title. BD2412 T 14:09, 2 December 2022 (UTC)Reply[reply]

Protocol (object-oriented programming)Interface (object-oriented programming)WP:COMMONNAME.

This is shockingly controversial. The entirety of the talk page is people being confused by the title and other people defending the title. But - I suspect mostly because of Java's popularity - "interface" is the more commonly used term.

Google results for interface oop: "About 9,450,000 results"

For protocol oop: "About 7,080,000 results"

Selected other references:

3mi1y (talk) 08:13, 7 November 2022 (UTC)Reply[reply]

Support per nom.--Ortizesp (talk) 17:05, 7 November 2022 (UTC)Reply[reply]
Support with comment: How related are the concepts of "protocol" and "interface" anyway? The way this article describes protocols (which is notably unsourced), it does indeed seem more akin to a communication protocol—I've never known interfaces to describe things like message format. I think the best thing is going to be rewriting the bulk of this article at Interface (object-oriented programming), with a short section talking about protocols in languages like Swift. Or, if significant notability can be established for "protocol" as independent from "interface", they should be two separate articles. But that does not seem to be the case. WPscatter t/c 17:45, 7 November 2022 (UTC)Reply[reply]
I don't know. The article itself seems confused by this:
Protocol is a term [...] which other languages may term interface
When used otherwise, "protocol" is akin to a communication protocol [emphasis mine]
Some programming languages provide explicit language support for protocols/interfaces
I read these as "this sense of the word is the same thing as an interface, but there's another thing called communication protocol and that's a different thing with its own article".
But then it occasionally goes back to talking about the latter anyway: (For the communications-style usage only:) The call sequence and decision points of the methods
And arguably confuses it with a third thing (design by contract): The invariants that are preserved despite modifications to the state of an object.
The only thing I see supporting a separate article on protocols in this sense is:
Note that functional programming and distributed programming languages use the term protocol akin to the communications usage
I haven't used whatever languages this is referring to, so this may or may not be enough of a thing for a separate article (vs a "some languages add more stuff to this" section); I'd have to do more research to form an opinion. 3mi1y (talk) 18:51, 7 November 2022 (UTC)Reply[reply]
The many references to communication protocols in this article are IMHO distracting and unfortunate. As far as I can tell the object-oriented concept of protocols came out of Smalltalk, where what is seen in later object-oriented languages as calls made between functions of different objects was modeled instead as messages passed between different objects. In that context it made sense to name "protocol" a collection of messages that certain types of objects could understand (see this 1981 article). But these were never actual communication protocols, and this article in its current state is IMHO confused and confusing when it associates the two different meanings of the term "protocol" everywhere, instead of just in a section discussing the history of the name (if that's even warranted).
This article is also confusing when it calls "protocol" a term rather than a concept. See my comment above about that.
Both the concept of messages and the concept of protocols introduced in Smalltalk are powerful. When later object-oriented languages came about, however, or when object-oriented features were added to other languages, these two concepts were not well known and some of these other languages used the existing and better-known concept of "interface" to implement that what had been previously known as protocols, even though that "interface" term already had a significantly different meaning. Now programmers who use those languages tend to use the term "interface" to refer to the concept of protocols, and either don't make a distinction between that concept and the more general concept of programming interfaces, or use qualifiers to make the distinction. In Java for example not only can the term "interface" be used to refer to both protocols in their original sense and programming interfaces in their original sense, but the corresponding keyword is used to implement these two different things! So many Java programmers never even see a distinction between the two concepts.
IMHO whether this article should be called "protocol" or "interface" depends on: 1) Which concept it should document ("protocol" in the original Smalltalk/Objective-C/Swift/Python/... sense of a collection of behaviors implemented by objects that have something in common even though they may be of different types or "interface" in the Java/C++/.. sense which is a combination of that "protocol" concept with the concept of the public face of an object independent of any of its implementation details); 2) How confusing it would be to have two different Wikipedia pages (Interfaces_(object-oriented_programming) and Interface_(computing)) that provide different definitions for the same term in the same general field; and 3) Given how precise the definition of the "protocol" historical concept has been, whether we should document here a more vague meaning of that concept, under a different names, simply because some programming languages (however popular they may be) chose to use as a keyword for the concept a term that had and still has a different meaning.
In general this shouldn't be a popularity contest. A change should be made only when justified by references, references which should not be popularity meters like web search query trends or results, nor the documentation of a particular vendor's language or software package, but instead published papers giving a good indicating of which terms are actually used in academia, industry, or elsewhere. We're entitled to our opinions but not to renaming articles solely based on them :-). IMHO and everything... TFJ76 (talk) 13:42, 11 November 2022 (UTC)Reply[reply]
Your point about having two pages about the same term in the same field is valid, and I would even support deleting this article, leaving it as a section of Interface (computing) (a section which already exists but could possibly be expanded). Based on personal experience I think the term interface is used in the field (academia and industry) much more than protocol when referring to this, but I don't have the sources to back that up. WPscatter t/c 18:17, 11 November 2022 (UTC)Reply[reply]
WP:COMMONNAME essentially is a popularity contest, and words change meaning over time. That a hypothetical 1970s-1980s Wikipedia would have used one word doesn't imply that's the clearest word to use now.
But I think there's validity in the rest of your points. What it comes down to for me is: are these two different words for the same thing, or two different things? I currently believe the former but I'm willing to be convinced otherwise. Either way, something needs reworking.
If they're essentially the same thing ± relatively minor language-specific differences, it seems clear to me that "interface" is the word people use for that thing now. I would, in this case, also support merging into Interface (computing) as Wpscatter suggests, and dropping the 'main article' link from there.
If there really is a substantially different thing called a protocol, this article should be rewritten to actually be about that, and not about interfaces or network protocols.
I suspect Concept (generic programming) also fits into this mess somewhere, but I haven't read it thoroughly enough to have a fully formed opinion on that yet. mi1yT·C 07:53, 12 November 2022 (UTC)Reply[reply]
Wanting more Real Sources for this is a valid point, so here's a brief sampling of sources on whether these are different things.
  • Messages are usually designed in sets to define a uniform interface to objects that provide a facility. Such a set of related messages is called a protocol. [...] When a message protocol is designed for a class, it should be made general enough to allow alternative implementations.[1] This sounds like an interface to me.
  • A program for extracting protocols, or sets of message names, directly from the Smalltalk system is described.[2] Again, no suggestion that there's more to it than a list of possible messages. The same paper uses "interface" many times to describe the same concept.
  • A protocol has additional structure, which we discuss in section 4.3. However, the interface of an object is always determined by its protocol..[3] Section 4.3 is too long to quote in full, but seems to be saying that "interface" is either a class's or an instance's set of messages, and "protocol" is the combination of the two. This, frankly, reads like pointless pedantry to me, but I do have a bit of a bias toward thinking that :)
  • prevention of violations of object protocols, i.e., restrictions on temporal orderings of method calls on an object[4] Probably the strongest counterargument. This is clearly talking about protocols as an additional thing describing how to call methods and not just what they are.
  • Recently, a lot of occurrences of "protocol" refer to communication protocols, because session types caught on as a research topic. I don't consider these especially relevant.
Languages in common use today that use "protocol" (Clojure, Swift, Python) all use it in the "interface" sense (list of method signatures that implementing classes must have). Java is listed there, but I can find no sources for that so I'm going to remove it.
mi1yT·C 09:37, 12 November 2022 (UTC)Reply[reply]
'Conditional support with comment' Oppose: This article could use a bit of cleanup, in all honesty. I am a bit biased myself (as I'm primarily a Java/C# developer), so I've personally only really encountered these things discussed as 'interfaces', not as 'protocols', but, taking a look at this article, I'm still not entirely sure what a 'protocol' is supposed to be. Yes, in the case of Python, it appears to be the Python name for an Interface, but then there's languages like Objective-C (having @protocol and @interface as distinct keywords) and Swift (apparently using 'protocol-oriented programming') which does make things a tad confusing.
Basically, upon reading this article, I'm not sure if the idea of a 'protocol' which this article is supposed to be about is 'the thing that I know as interfaces', or 'the process/theory of using things that I know as interfaces', or something else entirely. I'm assuming it's probably the former (ie that '"protocol" is a synonym for "interface"'), however, if protocols and interfaces are distinct concepts (ie that '"protocol" is the name for the process that "interfaces" (as I know them) are a component of'), then count this as an Oppose, a request for this to be made more clear in the article (and maybe add a section on how 'interfaces' relate to the whole idea of 'protocols' for the sake of everyone else who probably hasn't encountered the term 'protocol' used in whatever sense it's being used in within this article) 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talkedits) 05:30, 13 November 2022 (UTC); edited 14:00, 14 November 2022 (UTC) (explicitly opposing instead of supporting)Reply[reply]
Objective-C seems to use "interface" to mean a specific class's set of methods, and "protocol" to mean what Java/C# call interfaces.
Swift protocols seem to be interfaces with some extra features that don't really change the core concept. Protocol extensions sound a lot like C#'s extension methods; composition is just intersection types.
"Protocol-oriented" sounds like meaningless marketing buzzwords to me, but I haven't actually used it, and I've said the same about lots of other "*-oriented/driven" terms that most people seem to take seriously, so possible bias there.
Those seem to be the main two languages that actively use the term. (Python might in principle, but in practice, nobody in Python really talks about protocols to the extent more OO-focused languages do.)
(This is rapidly heading toward "no consensus because none of us can tell what the article is even about". That's a great sign.) mi1yT·C 07:35, 13 November 2022 (UTC)Reply[reply]
This is rapidly heading toward "no consensus because none of us can tell what the article is even about".
well, yes.
Then again, I've just had a cunning plan that might bypass this problem entirely. Perhaps it could be worth repurposing the Interface (Java) article into a more generic 'Interface type' article, specifically about interfaces themselves, briefly discussing how different languages offer this sort of functionality (similar to Enumerated type, Function type, Abstract type, etc). That way, there will be an article explicitly about interface types, allowing this article to focus specifically on whatever a 'protocol' is supposed to be. 🔥HOTm̵̟͆e̷̜̓s̵̼̊s̸̜̃🔥 (talkedits) 12:16, 14 November 2022 (UTC)Reply[reply]
  • Support per nom. This article, particularly as it stands now, but even before the recent extensive refactor, talks about the concept commonly called an interface; and interface (object-oriented programming) has always redirected here. I'm not sure if the other meanings of "protocol" above warrant articles, but if they do it's a separate article from this one and can be started after the move. Note that I also don't regard Interface (Java) as a sufficiently separate topic to warrant its own article, and would merge it into this one. Interfaces in Java, C# and other languages effectively function the same way so should be treated together.  — Amakuru (talk) 11:46, 28 November 2022 (UTC)Reply[reply]


  1. ^ Stefik, Mark; Bobrow, Daniel G. (15 December 1985). "Object-Oriented Programming: Themes and Variations". AI Magazine. 6 (4): 40–40. doi:10.1609/aimag.v6i4.508.
  2. ^ Cook, William R. (31 October 1992). "Interfaces and specifications for the Smalltalk-80 collection classes". ACM SIGPLAN Notices. 27 (10): 1–15. doi:10.1145/141937.141938.
  3. ^ Bracha, Gilad; Griswold, David (1 October 1993). "Strongtalk: typechecking Smalltalk in a production environment". ACM SIGPLAN Notices. 28 (10): 215–230. doi:10.1145/167962.165893. ISSN 0362-1340.
  4. ^ Beckman, Nels E.; Kim, Duri; Aldrich, Jonathan (2011). "An Empirical Study of Object Protocols in the Wild". ECOOP 2011 – Object-Oriented Programming. Springer: 2–26. doi:10.1007/978-3-642-22655-7_2.
The above discussion is preserved as an archive of a requested move. Please do not modify it. Subsequent comments should be made in a new section on this talk page. No further edits should be made to this section.

References for protocol vs. interface Edit

I decided to head to the library and find some more info about this topic. Reliable, secondary sources for these things are hard to come by online. I couldn't find anything hinting at the prevalence of interface vs. protocol, but I think these references do a lot in favor of the merge proposal. Courtesy pings: @HotMess @3mi1y @TFJ76

A protocol is an outline, or contract, of behavior that a type can implement. A protocol itself does not have any implementation; it is only a blueprint of methods and properties. Any type can adopt a protocol to help give it extra functionality to accomplish a particular set of tasks. Adopting a protocol is similar to a class inheriting from a superclass, although there is nothing to inherit with protocols. Rather, you adopt a protocol as a way of agreeing to abide by the contract it defines. Also, adopting protocols is not limited to classes like it is in Objective-C; Swift structs and enums can also adopt protocols.[1] This is very similar to most descriptions of interfaces I've encountered.

A Java application consists of interacting objects. An object interacts with other objects by sending messages. The ability of an object to receive messages is implemented by providing methods in the object's class.[2] The mention here of "sending messages" between objects is a strong point towards the sameness of protocols and interfaces.

An interface in Java defines a reference type to specify an abstract concept. It is implemented by classes that provide an implementation of the concept. Prior to Java 8, an interface could contain only abstract methods. Java 17 allows an interface to have static, private, and default methods that can also contain implementation. However, interfaces cannot have non-final variables. Interfaces let you define a relationship between unrelated classes through the abstract concept.[3]

Swift is a mixtape of different programming paradigms, because whether you take an object-oriented approach, functional programming approach, or are used to working with abstract code, Swift offers it all. As the major selling point, Swift has a robust system when it comes down to polymorphism, in the shape of generics and protocol-oriented programming, which gets pushed hard as a marketing tool, both by Apple and developers...[4] Point towards "protocol-oriented programming" being a marketing buzzword that does not establish protocols as a unique concept.

Protocols can act like interfaces; protocol extensions offer default implementations to types, helping you avoid rigid subclassing trees. Protocols, however, are trickier than they may seem and may surprise even the seasoned developer. For instance, let's say you have a protocol called FlavorType representing a food or drink item that you can improve with flavor, such as coffee. If you extend this protocol with a default implementation that is not found inside the protocol declaration, you may get surprising results! Notice in the next listing how you have two Coffee types, yet they both yield different results when calling addFlavor on them. It's a subtle but significant detail.[5] Following is a code sample in which the FlavorType protocol is created with an abstract addFlavor function, extended to add an implementation that prints "Adding salt", and adopted by a Coffee struct that implements addFlavor to print "Adding cocoa powder". A Coffee object is instantiated and used to call addFlavor which prints the cocoa message. A variable of the FlavorType type is created and initiated to the Coffee variable, and addFlavor prints the salt message. Though this whole passage seemingly contrasts protocols and interfaces, this seems like straightforward behavior to me, and is quite similar to some effects you see with C++'s abstract base classes and the like. Certainly it's a subtle difference and if this is the extent of it then I think they unquestionably do not warrant separate articles. WPscatter t/c 20:42, 16 November 2022 (UTC)Reply[reply]

Good finds, thanks! I added the first one to the article already because it directly answers an open question I had before (what word protocol-people use for "implement").
To be clear, that last one is just this Java#++ code:
abstract classerfaceocol FlavorType { addFlavor() { print("Adding salt"); } }
struct Coffee : FlavorType { addFlavor() { print("Adding cocoa powder"); } }

(new Coffee()).addFlavor() // cocoa
((FlavorType)new Coffee()).addFlavor() // salt
but in Swift? That seems like a reasonable result to me - you have a virtual and a non-virtual method with the same name, the first call doesn't do virtual dispatch because it's a concrete type, but the second looks at the vtable and sees the virtual one. mi1yT·C 06:20, 17 November 2022 (UTC)Reply[reply]
It was more like this:
protocol FlavorType { void addFlavor(); }
extension FlavorType { void addFlavor() { print("Adding salt"); } }
On top of the coffee stuff. Certainly both syntactically and semantically different from any interfaces I've worked with, but not drastically so. WPscatter t/c 07:21, 17 November 2022 (UTC)Reply[reply]


  1. ^ Miller, BJ (2015). Sams Teach Yourself Swift in 24 hours. Indianapolis, Indiana. p. 263. ISBN 978-0-672-33724-6.{{cite book}}: CS1 maint: location missing publisher (link)
  2. ^ Sharan, Kishori (2022). Beginning Java 17 fundamentals : object-oriented programming in Java 17 (Third ed.). [United States]: Apress. p. 798. ISBN 978-1-4842-7306-7.
  3. ^ Sharan, Kishori (2022). Beginning Java 17 fundamentals : object-oriented programming in Java 17 (Third ed.). [United States]: Apress. p. 806. ISBN 978-1-4842-7306-7.
  4. ^ Veen, Tjeerd (2018). Swift in Depth (1st ed.). p. 2. ISBN 9781617295188.
  5. ^ Veen, Tjeerd (2018). Swift in Depth (1st ed.). p. 5. ISBN 9781617295188.