私はこれを実装するための最良の方法を探しています。兄弟や子供と関係のあるオブジェクトを考えると、本質的には適合するパターンです。
各オブジェクトの状態を設定する一連の複雑なルールがあります
例えば
- 「タイプ」Aのn個の兄弟オブジェクトの場合、それぞれの状態はxです。
- n個の兄弟オブジェクト「タイプ」Aおよび「タイプ」Bの場合、それぞれの状態はyです。
これにはおそらく3つか4つのバリエーションがあります
各兄弟オブジェクトでは、その子オブジェクトの構成によって「タイプ」が決定されます。
これが十分に明確であることを願っています。さらに説明を追加できると思われる場合はコメントしてください。
編集:
いくつかの疑似コードを追加しました
状態はFooオブジェクト(FooBarまたはBarではない)と一緒に永続化され、状態はユーザー主導のイベントで更新されます(ユーザーはFoosとBarの組み合わせを修正して、イベントを生成し、状態を再設定できますそしてデータベースに固執する)
お役に立てれば
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
}