ChadSmiley Blog Things about family, life, coding, and more

11Jan/066

Simulating abstract classes

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.

  1. Create a new LotusScript Library
  2. Create a class as you would normally. I have created one called DaysOfTheWeek
  3. 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
  4. Declare a variable the same name as the class
    Dim DaysOfTheWeek As DaysOfTheWeek
  5. Declare the 'DaysofTheWeek' variable in the 'Initialize' Subrutine
    Set DaysOfTheWeek = New DaysOfTheWeek
  6. Save the script library, I named mine "Days of the Week"
  7. Create a LotusScript Agent, don't forget to se the agent target to none.
  8. Include the LotusScript library in the agent
    Use "Days of the Week"
  9. 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
  10. 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.

Filed under: Domino 6 Comments