I have 2 kotlin classes and both of them implement the interface myVariables. Inside myVariables is a variable named money. What I am trying to do is have the same variable(and keep its value too) be used inside both classes. Is this a good way to do it?
class MainActivity : myVariables, AppCompatActivity() {override val money = 0}
abstract class ShopActivity : myVariables, AppCompatActivity() {override val money = 0}
The interface:
interface myVariables {
val money: Int
}
What is a better way to use the same variable in both of my classes without redefining its value. For example if the variable has gained a value of 5 in the MainActivity class, I want to use the same variable with a value of 5 in the ShopActivity class.
I want the same effect as if this variable was global in the file that is using it, if that makes any sense.