这里是使用这些概念的另一个代码示例。
这个例子显示了一个内部方法,并假设另一个代码段识别了分发器对象。
This example shows an internal method and assumes some other piece of code has identified the dispenser object.
复制就意味着耦合,因为改变一条复制的代码意味着改变另一个代码。
Duplication always implies coupling, because changing one piece of duplicate code implies changing the other.
And to see that I've written another version of this, which I'm going to use here, where I'm going to give it a little indentation.
我已经写另一个版本的代码,我将把它用在这儿,我会在这儿加一点儿缩进。
And that shows you one other nice little thing we want to do, which is if I look in this code notice I set up a variable up here called false Solution Found, initially bound to false.
这显示了我们想要做的另一件事,那就是我在这段代码中设置了一个,名为Solution,Found的变量,初始值设为。
And notice, unlike Scratch where some of you might have realized it starts to get a little ugly, you have an "if else" and then you have another here and another one and things start to move and move and move like this, it gets very messy.
请注意,不像Scratch,在那里,你们其中某些人可能认识到它变得有点丑,你有一个“if,else“然后这里又另一个,那里又有一个,代码就像这样开始跳转,跳转再跳转,它开始变得有点凌乱了。
应用推荐