M
M
MonnWhiteborn2016-02-25 07:38:19
Java
MonnWhiteborn, 2016-02-25 07:38:19

What is the difference between protocols and abstract classes and interfaces?

The developers of the Swift language introduced a new paradigm, protocol-oriented programming. I read a little on this topic, but since I'm not strong in Swift, I didn't understand everything. Are there fundamental differences between these protocols and interfaces with abstract classes from Java?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LeEnot, 2016-02-25
@MonnWhiteborn

Well, for example, I see the differences:
- in the protocol, unlike the interface, it is possible to set variables that are reassigned by the class implementing the protocol
- the protocol is extensible
In general, as far as I understand, the protocol is a mixin. Those. you can write an implementation in it, unlike Java interfaces. Of course, static methods in Java 8 interfaces can be mentioned here, but, as for me, static methods are evil and they should die :) I'm probably overthinking now, but! When I read the description of Kotlin, the authors promised "If you don't like something in Java, then with a probability of 50% we have fixed it in Kotlin." Oops - I thought, thought of static methods and checked exceptions and got into the top ten.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question