我有一個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