如何将布尔值从内部包含类冒泡到外部包含类
我有 3 个类:
class A
{
public B b = new B();
public bool flag {get; set;}
}
class B
{
piblic 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.
}
}
从 C 的 foo 将 A 的标志设置为“true”的最佳方法是什么?
TIA
I have 3 classes:
class A
{
public B b = new B();
public bool flag {get; set;}
}
class B
{
piblic 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每次 C 更改自己的布尔值时,您的 C 都可以触发一个事件。您的 A 可以订阅事件并自行更新。您还可以将 A 的抽象接口传递给 b 和 C,让他们直接推送更改。
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.
另一个解决方案也是最简单的形式架构观点,但我不清楚在您的具体情况下是否可以接受,就是在 A 类中拥有一个
static
属性。以及 foo() 函数代码中的某个位置:
这很简单且清晰,但这取决于从应用程序架构的角度来看它是否可以接受。
希望这有帮助。
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.and somewhere in the code in your foo() function:
This is easy and clear, but it depends if it's acceptable from you app architectural point of view.
Hope this helps.