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 Wpscatter (talk | contribs) at 07:31, 7 November 2022 (Proposed merge of Interface (Java) into Protocol (object-oriented programming): 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]

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]

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]