Tips_namingconventions   >   Method Names
Method Names
The following are some general guidelines for method names:
- Method names should be between 8 - 20 characters long.
- Method names should clearly communicate what the method does or returns.
- Methods should do one and only one thing. ($promptclearcalculateSomeValues is not a good method)
- Use mixed case for variable names.
- Avoid use of the '_' underscore character in your method names. It makes them longer and more work to type.
- Do not name or create a method that evaluates to a not condition. (e.g $notNullBlankZero) Change the method logic so that it evaluates to a positive condition. (e.g. $isNullBlankZero). Doing so makes code which uses the method much simpler to read.
e.g. If not(fn.$notNullBlankZero) vs If not(fn.$isNullBlankZero)
- An X_ prefix designates an obsolete method.
Public vs Private Methods
Omnis Studio divides methods into two categories:
- Public Methods are visible to the world outside of the class. They show up in the Interface Manager. Public methods are made public by prefixing them with the $ character.
- Private methods are not visible to the world outside of the class. They do not show up in the Interface Manager. Private methods are made private by not prefixing them with the $ character.
The issue of public vs. private methods is very important to the object-oriented programming concept of information hiding, which allows you to write less fragile and easier to maintain code.
Public methods are the access points to an object's information and functionality. Private methods are the internal workings of the object.
You can modify private methods and even change private method names without breaking code in other classes.
Action vs Property Methods
As you get into object-oriented programming you will see two distinct categories of public methods.
- Action Methods: These are methods which do something. The naming convention for action methods is to begin the method name with a verb. The verb is alway in lower case. The rest of the action method name is in mixed case.
e.g. $checkEmailAddress, $sendEmail
- Property Methods: These are accessor methods to "values" ("states" or "attributes") which are stored in an instance of a class. Property methods use mixed case method names which do not begin with an action verb. Property methods are prefixed with $: so that they group separate from action methods in a list of property and action methods.
e.g. $:DataList, $:UserName, $:SessionName
Property methods must never have parameters. If you want to add a parameter to a property method to control what result the property method returns to you or what action it takes to get the result, you don't have a property method. You need to create a $ret prefixed action method.
- Assign Property Methods: You may want to make properties assignable. To do so add a property method to the class with the suffix .$assign
e.g. $:UserName.$assign
The assign property method should only have one parameter, the value to assign to the property.
e.g. Do secur.$:UserName.$assign('Craig')
You could use a $setUserName method name to accomplish the same thing; however by using the $assign method name suffix, the assign method shows up directly below its property method in sorted lists and your code looks more Omniscient.
Protected Methods
When you are working with a superclass/subclass structure there will come a time when you create a private method in the superclass, but then later when working in the subclass realize you need to access the private superclass method.
The simple solution is to to change the private method to a public method by adding a $ prefix to the superclass method name.
actionSuperClassMethod
changes to
$actionSuperClassMethod
The problem with this solution is the method that was intended to be private now shows up as a public method in the Interface Manager along with all the other public methods. The clean public interface to the objects now begins to get messing and non-subclass classes could call this once private method.
Some object-oriented programming languages allow you to create protected methods. In the object-oriented world protected methods can only be accessed by subclasses of a superclass. Omnis does not provide a way to create protected methods.
One solution is to prefix protected methods with
$_ (e.g.
$_actionMethodName) The
$_ prefix naming convention communicates to other classes that this method is meant to be accessed by subclasses of the class. The protected methods group separately in lists below the public methods.
Private Submethods
Public and protected methods are able to call private methods within the same class. This makes for a logical flow of method calls.
If you have a very long private method you may want to break it down into several private submethods which the private method calls. The private submethods are not meant to be called by the public or protected methods.
Private submethods are prefixed with the '
_' character. If you are writing a public method and need to call private method, using the '
_' prefix for a private submethod makes it clear you in to the public method that you should not call that method directly... it belongs to one or more of the private methods.
Method Dividers
For added clarity method dividers are used to separate the property, action, protected, private, and private submethods.
Each method divider consists of 5 dashes, a space, the methods category title, a space, and 5 dashes.
The following is a list of the method dividers used:
- ----- Property Methods -----
- ----- Action Methods -----
- ----- Protected Methods -----
- ----- Private Methods -----
- ----- Private Submethods -----
- ----- Obsolete Methods -----
Standard Method Prefixes
The following are standard method name prefixes.
- $ret is a prefix for a method which returns a value rather than true or false.
- $get is a prefix for a method which passes a value to the sender via a field reference parameter and returns true or false.
- $set is a prefix for a method which sets a value or something else in the target class instance.