Swift Protocol Hub

Swift Protocol Hub



According to Apple, declared on WWDC 2015, Swift is the first Protocol Oriented Programming (POP) language. As it seems Protocol is one of the core foundations for Swift learning. To have a better understanding of Swift one has to have a better understanding of Protocol. The Swift book from Apple covers all the basic parts related to the protocol. But here we are more concerned about the usage of Protocol. Such as how and when we should related protocol on our problem domain. In fact what specific problem protocol does resolve. What benefits we will have on using the protocol. Things like those are discussed all through on mobidevtalk through different blog posts. The purpose of this blog post, Swift Protocol Hub, is to list them all in one place. So that we can have a common place to start from.

As always we consider, you already have some reading on the protocol from the apple provided book or through any other medium. Because we will not cover the basic part of protocol on the blog posts. We are focusing on the protocol used on the real problems. Talking about the real problems, we will have some little to medium size use case-based problems to ease our learning of protocol. So let get started.

Background

At a glance

Now on Swift Protocol Hub we will be introduced with the following talks.

Let have some small review on each of the posts.

Inheritance, Initiator of coupling

One the first part of our protocol journey, Inheritance, Initiator of coupling, we talk about how we initiate the inheritance on the code base for removing the code duplicity. We also talked about the benefit of inheritance we can have. But moreover how this simple benefit can lead us to a very tightly coupled code, which slows us down to adapt to the ever-changing requirements.

Composition, breaker of chains

In the second talk, Composition, breaker of chains, we move our focus to composition. Which enables us to adopt the requirements changes far more quickly and easily than the typical inheritance. We build a Justice league(theoretically of course 😉) and resolve the issues we had with inheritance way. We talk about multiple inheritances and finish that talk with the pros and cons of composition.

Protocol, Swift way of thinking

This talk, Protocol, Swift way of thinking, can be the center of protocol-based talking on mobidevtalk. Because here we talk about the core concepts of protocol usage. So things like why we need to use protocol and why it is the best choice on Swift are discussed here. This time we bring the Avengers(again theoretically 🤓) to provide us the protocol-oriented programming concepts. Basically, this blog post is the very first step of protocol first thinking patterns on this blog site.

Introduction of Dependency Inversion on Swift

From this talk, Introduction of Dependency Inversion on Swift, we start to shift our focus more on the problem that protocol resolves. In that direction, the very first concept is dependency inversion. Here we talk about what is actually dependency inversion. Through the diagram of code example, we had an in-depth discussion over dependency inversion. Basically, this blog post is the go first when we need to know, how the protocol functions on Swift to have a swift way of coding.

Swift Dependency Inversion through Protocol

This talk, Swift Dependency Inversion through Protocol, is the star of the day. Because this part is the practical implementation of dependency inversion on Swift through the protocol. This blog post not only talks about the how-when of the protocol used for gaining dependency inversion but also the best possible way for achieving that.

Dependency Injection in Swift

Face it, Dependency injection is an alien for us. A very simple concept surrounded by some very unknown myths. But Dependency Injection need not be like that. Surely you will believe the same way after you read Dependency Injection in Swift. In this blog post, we first remove those myths and express the simple picture of dependency injection. Then gradually we start to implement the same concept on our swift code base. We discussed how the protocol can come in handy on dependency injection. We talked about the benefits and drawbacks of dependency inversion. In the end, we finish the talk with some tricks and tips to achieve dependency inversion on Swift.

associatedtype in Protocol

associatedtype is not always been very clear to us all. But in reality, associatedtype is not a very big deal. We just need four mins reading. That is it. Once we have a clear concept of the associatedtype we can move further to understand a lot more complex errors, which usually occurs when dealing with the generic protocol. So this blog post is an introductory one for a bigger concept, Generic Protocol.

End Talk

Whether it is inheritance or composition, there is no single way to go. Programming is all about choosing the balance. The right amount of balance is the sweet spot. But to find that sweet spot we need to have the necessary knowledge on each end. The knowledge about the pros and cons for each end will ease a lot for finding the proper balance. Swift Protocol Hub discusses the highlights of the post that gonna make us a bit more knowledgeable on the protocol domain and its related concepts. Hope you enjoy it. Take care.

Reference

6 thoughts on “Swift Protocol Hub

Leave a Reply

Notifications for mobidevtalk! Cool ;) :( not cool