Simulating abstract classes
Bookmark :
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.
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
- 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
Use "Days of the Week"
- 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.
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
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







Comments
I would rather call it an enumeration BUT an abstract class
Cordially
Alain
Posted by Alain H Romedenne At 05:31:03 AM On 01/12/2006 | - Website - |
Posted by Tim Tripcony At 08:22:50 PM On 01/11/2006 | - Website - |
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.
Posted by Kerr At 04:50:41 PM On 01/19/2006 | - Website - |
@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.
Posted by Chad Schelfhout At 06:30:32 AM On 01/12/2006 | - Website - |
Posted by Tim Tripcony At 09:40:13 AM On 01/12/2006 | - Website - |
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.
Posted by Chad Schelfhout At 07:23:37 PM On 01/19/2006 | - Website - |
Posted by Edward At 01:24:37 AM On 12/18/2009 | - Website - |