I have 3 classes:
class A
{
public B b = new B();
public bool flag {get; set;}
}
class B
{
piblic开发者_StackOverflow C c = new C();
}
class C
{
public void foo()
{
//iterates a dataTable with column "someBoolCondition"
// I want to set A's bool to true, after the first record that has 'true' in column
//"someBoolCondition". Thus is thought to avoid bool memebers in each class.
}
}
What it the best way set A's flag to 'true' from C's foo?
TIA
Your C can fire an event every time C changes its own bool. Your A can subscribe to event and update itself. You can also pass an abstracted interface of A to b and C for letting them push the change directly.
Another solution again, simplest form architectual point of view, but it's not clear to me if it's acceptable in your specific case, is just to have a static
property in A class.
public class A
{
private static bool failed = false;
public static bool Failed {get {return failed;} set {failed=value;}}
}
and somewhere in the code in your foo() function:
foo(...)
{
//failure happens!
A.Failed = true;
}
This is easy and clear, but it depends if it's acceptable from you app architectural point of view.
Hope this helps.
精彩评论