Jump to content

Talk:Interface (object-oriented programming)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TFJ76 (talk | contribs) at 11:33, 11 November 2022 (Victim of Misunderstanding: Reply). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
HighThis article has been rated as High-importance on the project's importance scale.

Disputed sense of protocol

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]

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]
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]
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. 62.178.250.9 (talk) 14:47, 17 March 2014 (UTC)[reply]

Merge with interface (Java)

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. 70.113.115.138 04:46, 20 February 2007 (UTC)[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]

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.--89.180.27.21 20:15, 3 May 2007 (UTC)[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]

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]

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]

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]

Merge with concepts in C++ STL

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]
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]

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 85.49.192.58 (talk) 20:25, 31 October 2007 (UTC)[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]
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. 200.127.223.79 (talk) 03:10, 1 June 2008 (UTC)[reply]

I think interface is the more common term

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]

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 http://www.artima.com/lejava/articles/designprinciples.html. 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]

Victim of Misunderstanding

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]

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]

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]

Only some languages

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]

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]

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]

Protocol?

Never heard of Interfaces being called Protocols ever, must be only on a few select languages. 200.3.193.162 (talk) 16:01, 8 October 2018 (UTC)[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]

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]
"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]
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]
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]


Requested move 7 November 2022

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:

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]
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]