Groundwork Support Forum
Community forum for Groundwork Open Source Products
 
 FAQ   Search   Memberlist   Usergroups   Register 
 Profile   Log in to check your private messages   Log in 

Constants, and how to use them in your Guava applications.

 
       Groundwork Support Forum Forum Index -> Open Forum
View previous topic :: View next topic  
Author Message
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.
Back to top
Display posts from previous:   
       Groundwork Support Forum Forum Index -> Open Forum All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group