I want to know whats the best practice when it comes to Class Initialization,
I mean should I initialize a Class once Customer c = new Customer(); in the top level, and use it everywhere in the class:
Tools tools = new Tools();
public boolean doCIdCheck(int cId) {
final Iterator<Customer> cursor = tools.Customers.iterator();
while (cursor.hasNext()) {
if (cursor.next().getCIdCheck(cId)) {
return true;
}
}
return false;
}
or should I just use new Customer().checkCId(); where ever I need it:
public boolean doCIdCheck(int cId) {
final Iterator<Customer> cursor = new Tools().Customers.iterator();
while (cursor.hasNext()) {
if (cursor.next().getCIdCheck(cId)) {
return true;
}
}
return false;
}
Or best to have each function/method have its own instance of a class:
public boolean doCIdCheck(int cId) {
Tools tools = new Tools();
final Iterator<Customer> cursor = tools.Customers.iterator();
while (cursor.hasNext()) {
if (cursor.next().getCIdCheck(cId)) {
return true;
}
}
return false;
}