Last active
March 6, 2019 15:01
-
-
Save NsAveek/f0a8f0b8b26149197c423b8965caf53a to your computer and use it in GitHub Desktop.
Interface for Strategy Design Pattern
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
interface IBaseStrategy { | |
fun isEnable(enable : Boolean) | |
} | |
interface IPendingStrategy : IBaseStrategy{ | |
} | |
interface IErrorStrategy : IBaseStrategy{ | |
var OnReUpload : (result : Result)-> Unit | |
} | |
interface IManageStrategy : IBaseStrategy{ | |
var OnManage : (result : Result)-> Unit | |
} |
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
when (getStatus(result)) { | |
"Error" -> { | |
errorStrategy.apply { | |
isEnable = true | |
OnReUpload = view.reUpload | |
} | |
} | |
"Pending" -> { | |
pendingStrategy.isEnable = true | |
} | |
else -> { | |
manageStrategy.isEnable = true | |
manageStrategy.OnManage = view.openManage | |
} | |
} |
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
class ManageStrategy : IManageStrategy { | |
var isEnable = false | |
var primaryTextColor = true | |
var secondaryTextColor = false | |
override lateinit var OnManage : (result : Result)-> Unit | |
override fun isEnable(enableOrDisable: Boolean) { | |
isEnable = enableOrDisable | |
} | |
} | |
class PendingStrategy : IPendingStrategy { | |
var isEnable = false | |
var primaryTextColor = true | |
var secondaryTextColor = true | |
override fun isEnable(enableOrDisable: Boolean) { | |
isEnable = enableOrDisable | |
} | |
} | |
class ErrorStrategy : IErrorStrategy { | |
var isEnable = false | |
var primaryTextColor = false | |
var secondaryTextColor = false | |
override lateinit var OnReUpload : (result : Result)-> Unit | |
override fun isEnable(enableOrDisable: Boolean) { | |
isEnable = enableOrDisable | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment