Blogs

  • Browse Blogs
  • My Blog
  • My Updates

Tags Help

  • View as cloud  | list

Similar Entries

photo

Compile Problem fixe...

Blog:  Jan Schulz
Jan Schulz
Updated 
No Ratings 0     No Comments 0
photo

Sending Designer int...

Blog:  Jan Schulz
Jan Schulz
Updated 
No Ratings 0     Comments 1
photo

Fun with ... garbage...

Blog:  Jan Schulz
Jan Schulz
Updated 
No Ratings 0     No Comments 0
photo

I was wrong: plus is...

Blog:  Yellow is the...
Tim Tripcony
Updated 
No Ratings 0     Comments 2
photo

Recompile in 8.0.2

Blog:  Urs Meli
Urs Meli
Updated 
No Ratings 0     No Comments 0

Dogear Bookmarks

.Domino Framework

Blog Authors:  Peter Presnell  

Previous |  Main  | Next

Implementing abstract classes, sealed classes, and interfaces in LotusScript

Peter Presnell  |     |  Tags:  lotusscript oop .dominoframework classes  |  Comments (0)
This post was prompted after following all the fun Tim Tripcomy was having building a mini-framework to demonstrate remote event binding....

Rather than just getting frustrated with the lack of progress by IBM in developing the LotusScript language - in line with Microsoft's version of BASIC (VB.Net) - I started building the .Domino Framework.  This was my way of getting more out of LotusScript so that I could be even more productive.  And it works. I find that by using a framework I can build new Notes applications around 50% faster than before.  And we ALL know that Notes development is already signficantly faster than most (All?) other development platforms - right!!?  LotusScript currently falls short in providing a number of important OOP concepts, including abstract classes, sealed classes, and interfaces. Within the .Domino Framework I have chosen to implement these constructs as described below.  Note: One of the key difference with LotusScript is that errors for violating "the rules" are thrown at run-time and not at compile time.  Other OOP languages such as C#, VB.Net, and Java implement these OOP constructs with class modifiers such as "abstract", "sealed", and "interface" (can you guess which is which?).  These languages stop you making mistakes when you first try to write the errant code.

Abstract Classes
An abstract class is defined as a way of providing attributes (properties, methods, and events) that can be shared by subclasses.  e.g. An Employee class defines attributes common to FullTimeEmployee, PartTimeEmployee, and Contractor classes.  The employee class is deemed "abstract" if you cannot implement an employee class directly but must implement one of the available subclasses.  An abstract class can be simulated in LotusScript by using the constructor.  When an instance of a class is defined the constructor of ALL base classes are also invoked.  We can therefore do a check to ensure the class being implemented is not the abstract class itself:-
Class AbstractClass
    Sub New(Source As Variant)
        If Typename(Me) = "ABSTRACTCLASS" Then
            Error ERROR_USER_FATAL,"AbstractClass is abstract and cannot be implemented directly"       
            Exit Sub
        End If
    End Sub
End Class


Sealed Classes

Sealed classes are used when you wish to prevent a class being extended by another class.  Again the constructor can be used to validate sealed classes.
Class SealedClass As AbstractClass
    Sub New(Source As Variant)
        If Typename(Me) <> "SEALEDCLASS"     Then
            Error ERROR_USER_FATAL,"SealedClass is sealed and cannot be extended by " + Typename(Me)
            Exit Sub
        End If
    End Sub
End Class


Interfaces

Like abstract classes, Interfaces are not designed to be implemented directly.  They differ from abstract classes in that they provide no code for properties, methods, events but define the properties, classes, and events that must be present for a class to meet the requirements of the interface. e.g. in Tim's example he has certain methods that must be implemented to make a specifc class "bindable remotely" This could be achieved by implementing an IsBindable Interface.  Another common example would be an "IsSortable" interface that is used to define classes that can be sorted.  Classes implementing such an interface may require GetFirst, GetNext, and Compare methods for a sort function to work.  Interfaces are more challenging to implement in LotusScript.  Because we are restricted to extending classes in a single chain we can only implement multiple interfaces by definining them in the underlying base class(es).  In C# we could implement multiple interfaces by listing each required interface as part of the class definition.  e.g. if I have interface A, B, and C I cannot easily implement classes in LotusScript with interface requirements A, B ,C, AB, AC, BC, and ABC without repeating a LOT of code (YUK).  We also have no way of checking if all of the required properties, methods, events have been implemented correctly, rather we can merely thow an error when we attempt to invoke one of those attributes.  The code for an interface could look something like this....
Class Interface
    Sub New(Source As Variant)
        If Typename(Me) = "INTERFACE" Then
            Error ERROR_USER_FATAL,"Interface is defined as an interface and cannot be implemented directly"
            Exit Sub
        End If       
    End Sub   
    Sub Method1
        Error ERROR_USER_FATAL,Typename(Me) + " has not implemented method Method1"
    End Sub
    Sub Method2
        Error ERROR_USER_FATAL,Typename(Me) + " has not implemented method Method2"
    End Sub
End Class


The next release of the .Domino Framework will provide an example agent that demonstrates the above.

Comments

Previous |  Main  | Next
Skip to main content link. Accesskey S
IBM Lotus Connections Help Tools About

Tags

A tag is a keyword that is used to categorize an entry. To view the entries with a particular tag, click a tag name or enter a tag in the box.
The tag cloud indicates the frequency of tag use. Popular tags appear darkest. The slider control adjusts how many tags are displayed in the tag cloud.