Skip to content

Instantly share code, notes, and snippets.

@manoj-mili
Created November 8, 2021 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-mili/ce94b2d6b8af8d3eb91ef481c6ae7327 to your computer and use it in GitHub Desktop.
Save manoj-mili/ce94b2d6b8af8d3eb91ef481c6ae7327 to your computer and use it in GitHub Desktop.
Use Wrappers Around Libraries
//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