🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.programmer
1 messages
1 total messages Started by Robert D. Nicholson Fri, 07 Aug 1992 04:34
Delegate methods
#477
Author: Robert D. Nicholson
Date: Fri, 07 Aug 1992 04:34
52 lines
2110 bytes
I am finding im still using case analysis with delegate methods, for example.

I have two textFields for which I need some similar action for. There textDidGetKeys
looks like this.

- textDidGetKeys:textObject isEmpty:(BOOL)flag
{  
    Matrix *matrix = nil; 
    TextField *textField;
    const char *s;
    int i, max;
    
    textField = [textObject delegate];
    
    if ([textField isEqual:employeename])
        matrix = [employees matrixInColumn:[employees lastColumn]];
    else if ([textField isEqual:description])
        matrix = [rooms matrixInColumn:[rooms lastColumn]];
      
    s = [textField stringValue];
    max = [matrix cellCount];
          
    [window disableFlushWindow];
    [matrix clearSelectedCell];
    if (!flag) {
        for (i = 0; i < max; i++) {  
            id cell = [matrix cellAt:i :0];
            if (strncmp(s,[cell stringValue],strlen(s)) == 0) {  
                [matrix selectCellAt:i :0];
                [matrix scrollCellToVisible:i :0];
                break;
            }
        }
    }
    [matrix display];
    [[window reenableFlushWindow] flushWindow];
    return self;
}

Notice the if tests, what can be done to elemimate this, (does it have to be eliminated?)
Short of creating a DelegateAgent class where the number of instances = number of
textFields?  Sounds reasonable, except that you then won't be able to connect
textDelgate in IB then, I guess you can do this in code, but as we always say we
would like to use IB at much as possible.

case analysis isn't a particularly object-oriented way of doing things.


-- 
Quote of the day

  "If Andrew Stone can do it, well Im certainly gonna give it a try"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads