"Lazy" is used in two different contexts.
The first, when critiquing a class design, argues that a class is ineffectual -- that it doesn't do enough to justify its existence. People also call this kind of class "thin." This is probably not what you mean here.
Second, lazy evaluation and lazy instantiation mean that the class only does the work of evaluating a property or initializing itself when actually needed.
For example, suppose we have a class that makes an Employee object.
@implementation Employee
- (id) initWithID: (IdentificationCode*) ident
{
self =[super init]
if (self) {
_records=[self retrieveEmployeeRecordsFor: ident];
_identification=ident;
}
return self;
}
This is fine, but retrieving all the records from a database might be slow. And sometimes we don't need to do the work. For example:
- (BOOL) isFounder
{
if (indent.number<10) return YES;
return NO;
}
If we're instantiating an Employee simply to find out if they're a Founder, we don't need to look up their records at all!
.....
if ([thisEmployee isFounder]) {
[self sendCandyTo: thisEmployee.identification];
}
On the other hand, sometimes we need them:
- (NSArray*) payments
{
return [self.records retrievePayStubs];
}
So, if we're constructing an Employee just to call isFounder
, we waste a database lookup. But we can't just skip that, because payments
needs it.
What we do is take the database lookup out of the constructor and put it in a load
method.
- (void) load
{
if (records) return;
self.records=[self retrieveEmployeeRecordsFor: ident];
}
- (NSArray*) payments
{
[self load];
return [self.records retrievePayStubs];
}
Now, we only load the employee records when we actually need them. If they've already been loaded, we don't do any extra work (aside from one method call). If we never need the payment records, then we don't need to do the work at all.
The class only works when it has to -- and waits 'til the last minute to do the work. It's "lazy!"
_getObjc2NonlazyClassList
which seems to get a list of lazy classes (I'm not sure yet), not a lazy class list. – Lipography