Ok guys, I need some help with basics. I'm creating a class that references an API and I have a few basic questions. I need the API to first connect and validate then I need it to offer up each part of the response. So here's my logic...
Class getBalance(){
function validate(){
Do validation...
}
function getAmount(){
var amount = obeject->amount;
return amount;
}
function getDate(){
var amount = obeject->date;
return date;
}
function getCount(){
var amount = obeject->count;
return count;
}
}
Ok so my first question is... Should the validate be handled in the constructor? It doesn't need to run every time the call is made, I just need to hit the API one time. Wouldnt putting it in the constructor cause it to call the api each time you call getBalance::getAmount(), getBalance::getDate(), etc? Or should the validation be completely seperate? Or should I return the the object from the validation and then pass it back to the class each time? Sorry I know it's basic, just looking for best practice! thanks.