![]() ![]() it creates a singleton that can be used across the app as a singular instance. it creates a module in Koin which would be used by Koin to provide all the dependencies. While working with Koin, there are few terminologies we need to understand before getting started. It is one of the easy DI frameworks which doesn't require a steep learning curve to get hold of it. Koin is a DI framework for Kotlin developers, completely written in Kotin. If you are not familiar with why we need a dependency injection framework in our project, click here In this blog, we are going to learn about Koin, a new dependency injection framework for Android Developers. but something I never knew about Java is that it doesn't support passing functions! You have to use Callable, a class, to pass functions.We have been using the Dependency Injection framework quite a few times like Dagger in our project. and then I wondered why I needed this at all? Why is Collections.sort taking a class as the second parameter? Why not just pass in a function, since that is all that is actually needed? Both C# and Kotlin supports passing functions so this is possible. The key difference is an abstract class can have state while the logic in an interface needs to be stateless!Īs I was working on the Koan, I was delighted by the SAM syntax. So why does Kotlin have interfaces and abstract classes?.The reason is that an interface in Kotlin is closer to an abstract class than in C#, to the point it can have functionality - yup, interfaces can have functions and logic! In C# only state that your are overriding when you inherit from a function and you actually override a function. In C#, when you implement an interface you do not need to state that you are not overriding the functions (see this example). ![]() Why do classes which implement an interface use override?.These Koans have given me more thoughts about the language than probably any previous Koans: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |