Hey guys, I have a question about Booleans and OOP.
Say I have 3 class, Class A, B and C.
Class C contains the boolean variable which will determine whether an option is in default of custom mode.
Class A controls the boolean state of Class C from detecting which buttons are inputted by the user.
Class B reads from Class C's boolean state to see whether it should generate a default answer or custom answer.
The problem I'm having is, after giving both Class A and B Class C's inheritence for the boolean, both A and B's inherited boolean seems to be a completely different set of boolean (When alterations are made on A, I assume A would alter the boolean state in C, thus returning the result to A as false, but B still thinks it's true).
Is there a reason for that? Or am I having the wrong programming logic here
?
unless your boolean is a static variable or class C is a singleton, the reference to class C in A and the reference to class C in B are different so that boolean is different.
to remedy, use a public static property (which both A and B would reference by using C.yourboolean) or make C a singleton class so both A and B reference the same class instance.
North America
Europe, Middle East and Africa
Asia Pacific