带数组的Java类
我有一个Java类,用于一家公司,它在全国各地有不同的分支机构,每个分支机构都会跟踪其客户列表。我如何实现这一点,使“伦敦”分行只提取使用过该分行的客户列表,而无法查看其他分行的客户列表?我正在考虑一个包含数组的客户机类,但我正在努力找到一种将这些类链接在一起的方法带数组的Java类,java,arrays,Java,Arrays,我有一个Java类,用于一家公司,它在全国各地有不同的分支机构,每个分支机构都会跟踪其客户列表。我如何实现这一点,使“伦敦”分行只提取使用过该分行的客户列表,而无法查看其他分行的客户列表?我正在考虑一个包含数组的客户机类,但我正在努力找到一种将这些类链接在一起的方法 public class Branch implements Manager { //instance variables that will be available to children of Branch private
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";
}
那么:
Map<String, List<Clients>>
Map
?
因此,您可以将分支映射到客户列表。如果
伦敦船级社扩展分支
和格拉斯哥船级社扩展分支
,则伦敦
将无法获取格拉斯哥
的私有字段伦敦
和格拉斯哥
甚至无法访问分行
使用
protected
或package protected access修饰符。您确实意识到,如果将数组作为类的私有成员放置,则只能直接访问特定对象?当然,但将创建分支类的实例,这意味着“伦敦”将能够看到“格拉斯哥”的客户端列表?