I have used custom Classes within LotusScript some in the past, but am really starting to fall in lust with them as of late. Last August, I wrote a series of articles on using Lists to write decent reports in Notes. Well, this past week, I took things a bit further by creating my own classes to replace the Lists I had used before. Well, that's a bit misleading, because my classes were really objects that contained lists of other classes, that were lists of objects. Capice? Of course, I really blame all of this on Jerry and his damn SnTT Tip.
While I don't think that the change to using classes for this agent saved me any coding over my procedural code I had before, it did allow me to control the data integrity better and hopefully improve the performance of the application. One thing I did notice while developing my classes was that I started to change the way I viewed the data and actions I wanted to perform. Everything started to look like objects and I started to see the actions I wanted to perform as subs or functions for those objects. I am not sure if it made my code any clearer, but it certainly made my mind see what I had to do much easier. It also allowed me to be able to expand this report in the future without having to change any of the underlying data structure of the classes.
The easiest way to think of using classes is to see everything in Notes as a list. A database is just a list of notes, both data notes and design notes. A view is just a list of documents. A document is just a list of fields. A field is just a list of values. And so forth. Since everything is just a list, creating classes that handle those lists should be relatively easy. Just as a NotesDocumentCollection is a list of NotesDocuments, you could create a class called CatalogItems that could contain a list of attributes for a given item. Then you could create a class called Catalog that could contain a list of CatalogItems. Once you start, the variations and options seem almost endless, just like the first time you were introduced to Notes.
The most important new keyword you need to learn when creating custom classes is Me. Me is used to reference attributes of the class that you are working in using dot annotation. Just as you would use doc.UniversalID to get the document id for a Notes document, you can use Me.attname to get or set the value of the attname attribute. If an attribute is Public, it can be read and set directly by other code using dot annotation. If it's Private, it can only be read or set by functions and subs within this class. Basically, if you want to be able to control access to the attributes of a class, set them to Private and use Public functions within the class to get or set the variables. If this seems Greek to you, don't worry, it did to me too. If you have any questions, feel free to respond here or ask more knowledgeable people like Wild Bill. H is knowledge of OO programming makes me proud to be a Scot.
So basically I created a class that was my entire results table. That class had a number of attributes, the most important of which was the one that was a List of rows. The rows were another class that had contained the values for each column as attributes. And since the values of the classes are loaded into memory, any manipulation or retrieval of the data is significantly faster.
Later on this week (think Thursday) I will release a class I wrote to calculate elapsed time, both total and business. A simple example such as that should help if you are still having trouble visualizing what I am talking about.