Navigation:  Appendix B: Dolphin Pattern Book > External Interfacing Patterns >

External Method Selector

Previous pageReturn to chapter overviewNext page

Context

When implementing the function calling methods in an External Library, there are frequently a large number of functions to be supported. Implementing all of these would consume a large amount of time, and waste memory in unused methods that might never be called. However, if methods are implemented on a demand basis, a standard form for the Method Names is required to simplify creating, reading and finding such methods, and avoid the possibility of multiple definitions of the same method with different names.

Solution

Use an algorithm to generate suitable message selector from the function help or header file prototype. The algorithm permits no arbitrary choices, preventing name collisions, and problems merging when more than one party adds the same external function.

A suitable algorithm is:

1.Form the first keyword of the selector from the entire function name, with a colon appended if the function has arguments. Underscores are removed by substituting Word Capitalization. The first letter of the selector is always lower cased.
2.Subsequent keywords are formed from the names (not type names) of the arguments, not including the first, as copied from the help file definition. The first letter is always lower cased, and again underscores are removed, if present.

Using this scheme, two different programmers should always come up with the same selector name from the same help file definition.

Example

appendMenu: hMenuDrop uFlags: styleFlags uIDNewItem: menuId lpNewItem: menuText

  "Appends a new item to the end of the specified menu with the specified

  style, identifier and text.

  BOOL AppendMenu(

      HMENU hMenu,        // handle to menu

      UINT uFlags,        // menu item flags

      UINT uIDNewItem,    // menu item identifier or pop-up menu handle

      LPCTSTR lpNewItem    // menu item content

      );"

  <stdcall: bool AppendMenuA handle dword dword lpstr>

  ^self invalidCall

 

Known Uses

All external methods in the base system libraries (e.g. UserLibrary, KernelLibrary) have selectors generated in this way.

Related Patterns

External Library, Method Name