-1

したがって、子MVVMを持つベースMVVMを持つWPFアプリケーションがあります。答えをグーグルで調べてみましたが、技術用語がよくわからなかったので、以下に2つの例を示します.おそらく誰かが例の効率について少し洞察を与えることができます. オーバーヘッドにほとんど差がないのか、それとも有意な差があるのか​​を知りたいです。

次のような設定があるとしましょう

public class ParentViewModel
{
    public ParentViewModel()
    {
        Child = new ChildViewModel();
    }

    public ChildViewModel Child { get; set; }
}

public class ChildViewModel
{
    public ChildViewModel()
    {
        GrandChild = new GrandChildViewModel();
    }

    public GrandChildViewModel GrandChild { get; set; }
}

public class GrandChildViewModel
{
    public GrandChildViewModel()
    {
        GreatGrandChild = new GreatGrandChildViewModel();
    }

    public GreatGrandChildViewModel GreatGrandChild { get; set; }
}

public class GreatGrandChildViewModel
{
    public GreatGrandChildViewModel()
    {
         intA = 1;
         intB = 2;
         intC = 3;
    }

    public int intA { get; set; }
    public int intB { get; set; }
    public int intC { get; set; }
}

そして、次の 2 つの使用例は、洞察が必要な場所です。

例 1:

public Main()
{
     var parent = new ParentViewModel();

     Console.WriteLine($"A: {parent.Child.GrandChild.GreatGrandChild.intA}" +
                       $"B: {parent.Child.GrandChild.GreatGrandChild.intB}" +
                       $"C: {parent.Child.GrandChild.GreatGrandChild.intC}");
}

例 2:

public Main()
{
     var greatGrandChild = new ParentViewModel().Child.GrandChild.GreatGrandChild;

     Console.WriteLine($"A: {greatGrandChild.intA}" +
                       $"B: {greatGrandChild.intB}" +
                       $"C: {greatGrandChild.intC}");
}

どちらがより効率的ですか?例 2 は、一度最下位レベルに下がってから intA、intB、および intC にアクセスするため、より効率的であると思われるため、質問しています。これは問題ですか?パフォーマンスの違いは重要ですか?

4

3 に答える 3