Friday, July 27, 2018

Multiple Inheritance using protocols, Diamond Problem


Multiple Inheritance is not available in Swift language.

If you try you end up with below compile time error.





We can achieve Multiple Inheritance using protocols in Swift. Combining behaviours and creating a concrete class using protocols.

What if we have same action in two protocols that my class in conforming to?




You will get a compiler warning as shown below.





We need to implement the method in our class to get rid of compiler warning.



This is the Diamond problem using Protocols for achieving Multiple Inheritance though compiler warns you.

Hope this post is useful. Feel free to comment incase of any queries.



No comments:

Post a Comment