Created
November 8, 2021 19:05
-
-
Save manoj-mili/ce94b2d6b8af8d3eb91ef481c6ae7327 to your computer and use it in GitHub Desktop.
Use Wrappers Around Libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Helper class which hides the library and exposes only required functionality | |
class ImageLoader { | |
fun setImageFromUrl(url: String, imageView: SomeViewHolder) { | |
// Do your Picasso or what ever library related stuff here | |
Picasso.get().load(url).into(imageView) | |
} | |
} | |
class SomeScreen { | |
// Don't do this it binds the library with the code | |
fun setImage(url: String) { | |
Picasso.get().load(url).into(someImageView) | |
} | |
// Do use the wrapper and let it take care of updating stuff | |
fun setImage(url: String) { | |
imageLoaderInstance.setImageFromUrl(url, someImageView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment