File:  [NeXTSTEP 3.3 examples] / Examples / EnterpriseObjects / Validation / Department.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:57 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

// Department.m
//
// Created on Wed Feb 15 09:50:50 GMT-0800 1995 by NeXT EOModeler.app Version 77

#import "Department.h"
#import "Employee.h"

@implementation Department

- (Employee *)lowestPaidEmployee
    // return the lowest paid employee.  We might want to do this via a query too
{
    // the server rather than by traversing the objects here...
    NSEnumerator *emps = [toEmployees objectEnumerator];
    Employee *emp, *lowestEmp = nil;
    while (emp = [emps nextObject]) {
        if (!lowestEmp || ([emp salary] < [lowestEmp salary]))
            lowestEmp = emp;
    }
    return lowestEmp;
}

- (NSString *)validateEmployee:(Employee *)emp
{
    // Lets say no employee can make more than 10 times the lowest paid
    // employee in his or her department
    Employee *lowest = [self lowestPaidEmployee];
    double limit = [lowest salary] * 10.0;
    
    if ([emp salary] > limit)
        return [NSString stringWithFormat:@"Salary exceeds departmental limit of %.2f", limit];
    return nil;
}

- (void)dealloc
{
    [departmentName autorelease];
    [toEmployees autorelease];
    [super dealloc];
}

@end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.