tdondich
Joined: 13 Feb 2006 Posts: 11 Location: Groundwork, San Francisco
|
Posted: Tue Mar 07, 2006 12:44 pm Post subject: Constants, and how to use them in your Guava applications. |
|
|
The previous posting in regards to using global "macro's" such as GUAVA_WS_ROOT has me wanting to touch base on how definitions *should* be used.
If you are writing a Guava application, you may want to use something similar to definitions. However, you'll want to be careful about clobbering other application's definitions. One way you could do this is prefix your definitions with the shortname of your application. All of Guava's definitions are prefixed with GUAVA_, and Status Viewer's are prefixed with SV_, as an example. However, this is not the optimal way.
The best way of doing this is by storing them as static properties of the relevant objects of your application. For example, if you have extended NavNode so you can create a lazy-load navigation tree, you may have some definitions to define what valid types of nodes you can create (this is something I had to do when refactoring the Bookshelf). I would do something like this:
class myappNavNode extends NavNode {
public static NAVNODE_BOOK = 1;
public static NAVNODE_DOCUMENT = 2;
public static NAVNODE_GREETING = 'Hello User!';
...additional class implementation...
}
The way to access these definitions would be by using myappNavNode::$NAVNODE_BOOK, for example.
Good programming practice for Guava applications. _________________ Project Maintainer for Guava, Status Viewer and Fruity at Groundwork Open Source. |
|