我正在寻找实现此目的的最佳方式,基本上是一种适合的模式,因为该对象与兄弟姐妹和孩子有关系。建议基于组件的模式选择对象状态
我们有一套复杂的规则来设置每个对象的状态
例如, “类型”的
- Ñ兄弟对象A,那么每个的状态为x
- Ñ兄弟对象“类型” A和“类型” B则每个的状态为y
有大概3个或4对这个
与每一个兄弟更多的变化对象及其子对象的组成将determe它的“类型”
希望这是很清楚,请你评个墨水我可以添加更多的澄清?
编辑:
加入一些伪代码沿侧的富objecst(不是FooBar的或酒吧)被保留
状态和状态被更新的用户驱动的事件(用户可以ammedn的FOOS和酒吧混的都然后生成事件reinterigate,设置状态和持久化到数据库)
希望这有助于
void Main()
{
var foobar = GrabAFooBar();
//Each Foo will have its state set based on the rules in the question
//eg
//foobar has 2 Foos both of which only contain BarType1 then both foos have a State of StateOne
//foobar has 2 foos, one has a BarType1 one has a BarType2 both foos have a State of StateTwo
//foobar has 2 foos, one has a BarType1 and BarType3 one has a BarType2 both foos have a State of StateThree
//effectivaly there are 5 States (currently) and a well defined set of combinations
//All foos will have the same state at the end of the process (there will never be a mix)
}
FooBar GrabAFooBar()
{
//return a FooBar from data
}
// Define other methods and classes here
class FooBar
{
List<Foo> Foos {get;set;}
}
class Foo
{
public List<Bar> Item {get;set;}
public State state {get;set;}
}
abstract class Bar
{
}
class BarType1 : Bar
{
}
class BarType2 : Bar
{
}
class BarType3 : Bar
{
}
enum State
{
StateOne,
StateTwo,
StateThree
}
你可以添加一些伪代码吗? – Nick 2012-04-05 15:19:12
'对于每个兄弟对象来说,它的子对象的组合会阻止它的“类型” - 类型为'状态'或实际上'类型' - 我认为你应该提供一些代码 - 使一些'FooA'和'等级' - 这很难遵循,可能意味着太多的东西。 – NSGaga 2012-04-05 15:27:53
@NSGaga我现在将研究一些代码,是的,他们都是“状态”,虽然父对象的状态只是通过对其子节点进行访问而存在,但这是通过一起询问兄弟节点来发现的状态,它需要在每个父对象 – Pharabus 2012-04-05 15:30:36