How to implement complicated interfaces with multiple overridden methods in Kotlin
SOLID is a mnemonic acronym that is used to define the five basic object-oriented design principles:
- Single Responsibility Principle
- Open-Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
The Interface Segregation Principle(ISP) states that if an interface becomes too long, it is better to split it into smaller pieces (interfaces) so that the client doesn't need to implement the ones in which they are not interested. In this recipe, we will understand what and why this is important.
Getting ready
We will be using Android Studio 3.0. Ensure that you have its latest version.
How to do it…
Let's see an example where ISP can help us:
- This is a simple example of a "fat" interface:
button.setOnClickListener(object : View.OnClickListener { fun onClick(View v){ // TODO: do some stuff... } fun onLongClick(View v){ // we don't need it } fun onTouch(View v, MotionEvent...