Suppose i have a class called CommandLineOperation
. This class accesses api resources. Thus i have defined one instance member of type APIAccessor
.
class CommandLineOperation {
APIAccessor apiAccessor;
void create() {
apiAccessor = new APIAccessor(email,password);
//do work for creation
}
void update() {
apiAccessor = new APIAccessor(email,password);
//do work for update
}
}
class APIAccessor {
String email;
String password;
APIAccessor(email,password) {
this.email = email;
this.password = password;
}
}
The operations in CommandLine, are infrequent, is it a better approach to instantiate APIAccessor
under every operations or create once using constructor of CommandLineOperation
class. e.g.
CommandLineOperation(String email,String password) {
this.apiAccessor = new APIAccessor(email,password);
}
Please let me know or suggest good coding design pattern. Or suggest me any reference book so that i can improve my coding standard based on the analysis. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire