Skip to content

Instantly share code, notes, and snippets.

@rommansabbir
Last active June 22, 2021 14:41
Show Gist options
  • Save rommansabbir/4edb4dc1e1649838be417a2afc4c56cd to your computer and use it in GitHub Desktop.
Save rommansabbir/4edb4dc1e1649838be417a2afc4c56cd to your computer and use it in GitHub Desktop.
Create a blueprint of your business logic for respective class/fragment/activity and clear the concern.
/*
Define all actions for a respective class/fragment/activity.
The reason to put all actions into a respective interface is to clear the concern.
So that we can easily identify the all business logic handle by this class/fragment/activity.
This interface will work like a blueprint of business logic for your class/fragment/activity.
*/
interface ProfileActions {
fun onBMETCard()
fun onMyDocuments()
fun onSettings()
fun onLogout()
fun onEditProfile()
fun onLanguageChange()
}
/*
In your class/fragment/activity initialize the *Action
*/
private val profileAction = object : ProfileActions {
override fun onBMETCard() {
// TODO
}
override fun onMyDocuments() {
// TODO
}
override fun onSettings() {
// TODO
}
override fun onLogout() {
// TODO
}
override fun onEditProfile() {
// TODO
}
override fun onLanguageChange() {
// TODO
}
}
/*
Call respective function by using *Actions instance
*/
ProfileMenuAdapter(activity, getMenuList(activity)) {
when (it.type) {
ProfileMenuType.BMET_CARD -> profileAction.onBMETCard()
ProfileMenuType.MY_DOCUMENTS -> profileAction.onMyDocuments()
ProfileMenuType.SETTINGS -> profileAction.onSettings()
ProfileMenuType.LOGOUT -> profileAction.onLogout()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment