• Browse Blogs
  • My Blog
  • My Updates

+Tags Get help with tags?

+ Similar Entries

photo

Adding the "X" Facto...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     CommentsComments 2
photo

Tagging Design Eleme...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     CommentsComments 1
photo

Add Discussion Threa...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     CommentsComments 2
photo

OO-SSJS: Object Orie...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     No CommentsComments 0
photo

Property Generator f...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     No CommentsComments 0

+ Bookmarks

+ Blog Authors  

Adding Abstract Classes To A Framework

Peter Presnell |   | Tags:  .dominoframework oop classes | Comments (2)  |  Visits (1,473)

After writing my blog about implementing abstract (and other) classes in LotusScript I started to think about ways to reduce the code that would be required to implement this into each and every abstract/sealed class in a framework.  I have now gone back to my own .Domino Framework and added a new base class that implements much of the logic for abstract/sealed classes (and interfaces). 

Class DominoClass
Sub New(Source As Variant)
Dim Params As Variant ' Parameters passed to this class
Select Case Typename(Source)
Case "STRING"
Params = Fulltrim(Split(Source))
If (Ubound(Params) = 1) Then Call ValidateClass(Params(0),Params(1))
End Select
End Sub
'/**
' * Validate a class to ensure it conforms to rules for special class types
' */
Sub ValidateClass(ClassType As String,ClassName As String)
Select Case ClassType$
Case ENUM_CLASS__ABSTRACT: ' Abstract classes cannot be implemented directly
If (Typename(Me) = ClassName$ )Then
Error ERROR_USER_FATAL,ClassName$ + " is abstract and cannot be implemented directly"
End ERROR_USER_FATAL
End If
Case ENUM_CLASS__INTERFACE: ' Interfaces cannot be implemented directly
If (Typename(Me) = ClassName$) Then
Error ERROR_USER_FATAL,ClassName$ + " is an interface and cannot be implemented directly"
End ERROR_USER_FATAL
End If
Case ENUM_CLASS__SEALED: ' Sealed classes cannot be extended
If (Typename(Me) <> ClassName$) Then
Error ERROR_USER_FATAL,ClassName$ + " is sealed and cannot be extended by " + Typename(Me)
End ERROR_USER_FATAL
End If
End Select

End Sub
End Class

Now any class that extends this class (directly or indirectly) can assert itself as being an abstract class, sealed class, or interface on one of two ways:

Constructor: The following  scenario can be used when the constructor shares the same footrpint as the base class (single parameter of type variant) and there is no need to pass the original parameter to any intermediate base/super class.  It work by directing the constructor of the base class to take an alternative value than the one passed to the extended class.

Class AbstractClass As DominoClass
Sub New(Source As Variant), DominoClass(ENUM_CLASS__ABSTRACT + " ABSTRACTCLASS" )
...
End Sub
End Class

Method: The alternative is to invoke the ValidateClass method directly

Class SealedClass As AbstractClass
Sub New(Source As Variant)
Call ValidateClass(ENUM_CLASS__SEALED,"SEALEDCLASS" )
End Sub
End Class
No RatingsRatings 0

Comments (2)

photo
1 Jan Schulz commented   Permalink No RatingsRatings 0

Seems quite a lot overhead just for checking if a class is extendable. Espcially for classes, which have no abstract classes in their parent.

photo
2 Thomas Bahn commented   Permalink No RatingsRatings 0

Hi Peter,

I have described a simpler way to simulate abstract classes in my blog:

Abstract classes concrete
http://www.assono.de/blog/d6plinks/Abstract-classes-concrete

Thomas

Add a Comment Add a Comment

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