我很难理解如何一起使用组合和接口来支持组合而不是继承?一个例子可以是:
界面:
public interface IMachine {
void TurnOn();
void TurnOff();
}
Run Code Online (Sandbox Code Playgroud)
Machine 类是 Printer 类的父类
public class Machine {
protected boolean isOn;
public Machine(boolean isOn) {
this.isOn = isOn;
}
public void TurnOn() {
isOn = true;
System.out.println("Machine is on !");
}
public void TurnOff() {
isOn = false;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我创建一个实现 IMachine 接口的打印机类,它将实现 IMachine 接口的方法。但是假设我创建了一个实现 IMachine 接口的 Clock 类,那么我必须再次实现这些方法。是否有更有效的方法来使用组合和接口并将方法委托给 Machine 类?
我正在尝试创建一个函数,它接受参数的数量并以下列格式返回一个列表:[a,b,c] => [[c],[b,c],[a,b,c] ]
def generate_list(arg):
list = []
for item in arg:
list.append(item)
return list
print(generate_list([1, 2, 3, 4, 5]))
Run Code Online (Sandbox Code Playgroud)
我知道上面的说法不正确.有人可以指点我正确的方向吗?
我设计了这种架构,其中所有测试用例都在 Amazon.robot 文件中,机器人框架的所有低级关键字都将在两个单独的文件中(AmazonGui.robot 和 Commons.robot)
包含所有测试用例的 Amazon.robot 文件:
*** Settings ***
Documentation This is some basic infor the whole suite
Resource Resources/AmazonGui.robot
Resource Resources/Common.robot
*** Variables ***
*** Test Cases ***
User must sign in to check out
[Documentation] This is some basic info about test
[Tags] Smoke
Common.Begin Web Test
AmazonGui.Search for Products
AmazonGui.Select Product from Search Results
AmazonGui.Add Product to Cart
AmazonGui.Begin Checkout
Common.End Web Test
Run Code Online (Sandbox Code Playgroud)
我还有另外两个具有低关键字的资源文件,所以基本上测试用例(Amazon.robot)正在调用低级关键字文件(Common.robot 和 AmazonGui.robot)。我已将资源文件导入到测试用例文件中。
AmazonGui.robot 文件,包含用于测试用例的低级关键字
*** Settings ***
Library Selenium2Library
*** Keywords …Run Code Online (Sandbox Code Playgroud)