Informal interfaces

Fredrik Olsson peylow at gmail.com
Mon Oct 2 05:01:48 PDT 2006


Fredrik Olsson skrev:
> I attach a file with a longer example fo how it could be useful and work 
> in a real world example.

Some other places where an informal protocol could be useful could be 
for a URL-request delegate:

interface URLRequestDelegate {
   optional bool acceptUnsignedCertificateForURL(char[] url) = true
   optional void userCredentials(char[] url, out char[] usr,
                                 out char[] pwd);
}

Delegating the work would be an easy task, be it automagic, or simply 
asking the user. And best of all the the delegate informal interfaces 
would be very clear views of what a class expects of the world. 
Self-documenting, and easy to model code.


Or as a data source delegate for a table view:

interface CellValue {
   char[] toString();
   optional void drawInRect(Rect);
}

interface TableViewDatasource {
   uint numberOfRows();
   CellValue getCellValue(uint row, uint col);
   optional void setCellValue(CellValue cv, uint row, uint col);
}

Where implementing numberOfRows and getCellValue are required, and would 
make a read only table. Optionally implementing setCellValue would make 
the table view editable as well.


// Fredrik Olsson



More information about the Digitalmars-d mailing list