Java allows the creation of abstract classes but currently LotusScript does not, but I have a way of simulating. There is no way of enforcing it but here is a way of implementing it.
- Create a new LotusScript Library
- Create a class as you would normally. I have created one called DaysOfTheWeek
Class DaysOfTheWeek
Public Function getWeekDay( dow As Integer )
Select Case dow
Case 1
getWeekDay = "Sunday"
Case 2
getWeekDay = "Monday"
Case 3
getWeekDay = "Tuesday"
Case 4
getWeekDay = "Wednesday"
Case 5
getWeekDay = "Thursday"
Case 6
getWeekDay = "Friday"
Case 7
getWeekDay = "Saturday"
Case Else
getWeekDay = ""
End Select
End Function
End Class
- Declare a variable the same name as the class
Dim DaysOfTheWeek As DaysOfTheWeek
- Declare the ‘DaysofTheWeek’ variable in the ‘Initialize’ Subrutine
Set DaysOfTheWeek = New DaysOfTheWeek
- Save the script library, I named mine “Days of the Week”
- Create a LotusScript Agent, don’t forget to se the agent target to none.
- Include the LotusScript library in the agent
- Just start using the class
Sub Initialize
Print "Today's Day of the week:" + DaysOfTheWeek.getWeekDay( Weekday( Now ) )
Print "Day of the week1:" + DaysOfTheWeek.getWeekDay( 1 )
Print "Day of the week2:" + DaysOfTheWeek.getWeekDay( 2 )
Print "Day of the week3:" + DaysOfTheWeek.getWeekDay( 3 )
Print "Day of the week4:" + DaysOfTheWeek.getWeekDay( 4 )
Print "Day of the week5:" + DaysOfTheWeek.getWeekDay( 5 )
Print "Day of the week6:" + DaysOfTheWeek.getWeekDay( 6 )
Print "Day of the week7:" + DaysOfTheWeek.getWeekDay( 7 )
Print "Day of the week8:" + DaysOfTheWeek.getWeekDay( 8 )
End Sub
- Run the agent and watch the status bar.
That is it! Simple, but accomplishes the task of creating abstract class in LotusScript. Just for the record I normal don’t declare global varibles like this.
Pingback: Line Break Class « ChadSmiley Blog
Great idea… you’re right, this isn’t a true abstract class, but similar. The main difference I can see is that any classes handled this way would be automatically loaded in to memory – whether you’d need it or not – if your code needs anything else in the same library. So you’d probably want to keep use of this to a minimum to conserve memory.
Hi Chad,
I would rather call it an enumeration BUT an abstract class
Cordially
Alain
@1 Tim – I would agree, but the memory would be very minimal because there is nothing contained in the class.
@2 Alian – In this example it could have been better to create an enumeration, but the implementation would be the same for an enumeration or an abstract class.
That’s true, this particular class wouldn’t eat up any memory. But a more complex class with lots of auto-initialized members would… ‘course, one could always structure the class in such a way that any usage of the class would first check to see if its members had been initialized. That way the class would always be available but create no overhead until needed… I think I may play a bit with this idea and let you know what I find.
Oh god, I think i’m going to get a reputation for negativity round here…
Anywho, from the java point of view, the important point about abstract classes is that you can’t instantiate them. A class that only has static methods is not the same thing. For example you can have a non-abstract class that only contains static methods. This may be a slightly academic point but from a java perspective it’s pretty important.
Now the positive bit
…
It’s been a long while since i did any LotusScript and didn’t do much in the way of defining my own classes when I did, so this might be a very useful technique for those delving deep with LS. Just don’t confuse this technique with what a java abstract class is, how it works and what it’s used for.
Kerr, keep the comments coming. Yes from a Java perspective I would agree with you that this should never be done. From a LotusScript perspective there is no such a thing as an abstract class everything has to be instantiated.
But some people, including me, like the concept of an abstract classes and this was the best way that I could come up with to ‘simulate’ one.