English 中文(简体)
问题与Hierarchy
原标题:Issue with Call Hierarchy

我有这样一种情况,即我用手提的方式来发挥职能。 见以下例子说明和问题。 我希望我对这一局势了解一些技术性话。 人们更容易理解我所说的话。

public static class test
{
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        if (Login("johndoe","password")) 
        {
            if(checkForSomething("johndoe"))
            {
                DoOpenDashboard();

                // Now it opens dashboard, it has several buttons. 
                // Each button does several different things
                // On this example I am just giving you two level of hierarchy
                // but in my actual program, there are 7 levels.
            }
        }
    }

    public static bool Login(string userid, string password)
    {
        //valid user
        return true;
    }

    public static bool checkForSomething(string userid) 
    {
        return true;
    }

如果儿童方法被拖延,我如何避免重新采用以前的电话方法/功能?

For example login method is calling checkForSomething("johndoe"). If checkForSomething("johndoe") is passed then it will open Dashboard window by calling DoOpenDashboard. At this point my process should should not go back to checkforsoemthing, and then login. I hope it makes sense.

问题回答

不清楚你在此再次要求什么。 你的假体编码显示, Log(login)方法在贵阶层的构造中被称作。 如果这确实是贵国的法典如何发挥作用,那么防止再次叫 Log洛因,你需要避免出现这一类别的新事例。

然而,我认为你真心要问Arrow的反家长:

rel=“nofollow” http://codinghorror.com/blog/2006/01/flattting-arrow-code.html

我试图避免复制和复制;过去,但由于原来的员额似乎不够明确,因此,从Coding Horror中挑选出一个与上述链接:

Where appropriate, I flatten that arrow code by doing the following:

  1. 用警卫条款取代条件。 该法典。

    if (SomeNecessaryCondition) { // function body code }

    作为一项看守条款开展工作:

    if (!SomeNecessaryCondition) { throw new RequiredConditionMissingException; } // function body code

(指出还有其他技术也列入清单,但我认为这第一技术现在就足够了)

这样,如果——一旦检查失败,每增加一次检查就会导致另一套检查。 也可以这样做,而不必提出例外,因为纽特1_ 浮标称一种功能,可回收一种ool(胜诉,因失败而伪造),并立即以失败的条件归还假:

private void button1_Click(object sender, RoutedEventArgs e)
{
    if (AllSystemsGo())
    {
        DoOpenDashboard();
    }
}

private bool AllSystemsGo()
{
    if (!Login("johndoe","password"))
        return false;

    if (checkForSomethingEvil("johndoe"))
        return false;

    if (!checkForSomethingImportant())
        return false;

    return true;
}

你们是否试图确保只检查过你的方法? 也许你需要多度询问一些财产,但只经过一次测试。

private bool? canLogin;
private bool? somethingOk;

private bool CanLogin
{
    get
    {
        if (canLogin == null)
            canLogin = Login("johndoe","password");
        return canLogin.Value;
    }
}

private bool SomethingOk
{
    get
    {
        if (somethingOk == null)
            somethingOk = checkForSomething("johndoe");
        return somethingOk .Value;
    }
}

private void button1_Click(object sender, RoutedEventArgs e)
{
    if (this.CanLogin && this.SomethingOk && // other checks) 
    {
        DoOpenDashboard();            
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签