我有一个Java类用于公司位于国家周围的不同分支,并且每个分支都将保留其客户列表的跟踪。我如何实现这一点,以便“伦敦”分支只拉取使用该分支的客户列表,但无法查看其他分支的客户列表?我想包含数组客户端类的,但IM苦苦寻找类连接在一起具有数组的Java类
public class Branch implements Manager {
//instance variables that will be available to children of Branch
private String branchName;
// constructor
public Branch(String name) {
this.branchName = name;
}
//Returns the location of the branch as a String
@Override
public String getBranch() {
return this.branchName;
}
//Returns a String representation of customers who have used the Branch
@Override
public String getAllCustomers() {
return "Customer list will go here";
}
你意识到如果你把数组作为类的私有成员,它将只能被特定对象直接访问? –
当然,但会创建分支类的实例,这意味着“伦敦”将能够看到“格拉斯哥”的客户列表? – user2904400