Interface segregation principle in swift | SOLID principle in swift

Hey there this is codecat15 in some of my past videos, you have seen how I use protocols to make my code, clean, manageable and testable. And in this video, I want to show if we are not careful while implemenitng a protocol so what you might end up is a fat protocol scenario What does a fat protocol mean? And how do we avoid fat protocols is what we will learn today before that, I want to request you if you like the videos I am making then please subscribe to the channel Share it with your friends who are iOS developers OR want to be an iOS developer would appreciate it. I have a protocol named Human which has 4 set of functionality I have a class over here named person which is implementing the human protocol over here i can code for sleep function I can even code for the eat function so this function is of no use to me here similarly a lion does not go to work, so this function too is of no use to me in the Lion class this is exactly what fat protocols are which means that In your class you have implemented a protocol which has some extra set of functions which is not required by your class at all so whenever you implement a protocol in a class just make sure that the protocol only has those functions which is needed by the class and no additional functions let’s add one more protocol named Animal and I will add only those functions which is needed by the Animal protocol and rather than implementing human I will just replace it with Animal and get rid of these two functions You have to be very careful when you are implementing protocol in any class you should ask question to yourself that does your class really need all the functions, you have in that protocol? and if you really need those functions then only implement that protocol else don’t, I would advise creating a new protocol something like this when I see my own code here I observe that I have two functions which is same so can I club these two functionalities into just a single protocol? over here you can add one more function to Animal protocol if you need for example, all animals for lunch, they don’t go in any resturants what they do is they hunt The person class looks OK, we don’t need to change anything here over here you are getting an error becauseyou added a new function you just need to implement it in your class

Tags: , , , , , , , , , , , , , , , ,

There are no comments yet

Why not be the first

Leave a Reply

Your email address will not be published. Required fields are marked *