Abstract classes concrete

by Thomas Bahn,
assono GmbH, Standort Kiel,

If you have some knowledge about other object-oriented programming languages, like Java, you probably like abstract classes. These are classes you cannot instanciate directly, i.e. create new objects from them. But you can derive other classes from them and create objects from these subclasses. In an abstract class you can have attributes and methods like in any other class.

Normally, abstract classes model some kind of concept or abstraction, for example Animal. There are dogs and cats, but no creature is merely an animal, its always of a concrete kind of animal.

In the abstract class Animal you put those attributes and members, which all animals have in common. Then you build subclasses like Dog or Cat, which add new or overwrite inherited members.

Other classes are abstract, because they have methods, which cannot be implemented at this level. Only concrete subclasses "know", how to implement them.

A typical example of this is a generic Sorter class with a Sort method. The concrete subclasses BubbleSorter, HeapSorter and QuickSorter overwrite the abstract Sort method with different implementations.

Unfortunately, in LotusScript there are no abstract classes. But there is a workaround, which can kind of simulate them:

Class AbstractClass

       Public Sub New()
               If TypeName(Me) = UCase("AbstractClass") Then
                       Error 1, |Abstract class: ? | & TypeName(Me)
               End If
       End Sub ' AbstractClass.New
               
       Public Sub Method()
               Error 2, |Abstract method: ...|
       End Sub ' AbstractClass.Method

End Class

Class ConcreteSubclass As AbstractClass
       
       Public Sub New()
               ' might be empty or not...
       End Sub ' ConcreteSubclass.New
       
       Public Sub Method()
               ' the implementation...
       End Sub ' ConcreteSubclass.Method
       
End Class ' ConcreteSubclass

Attention: The class name string in the if clause of the New method in the abstract class must match the class's name.

You can create an object from AbstractClass - the LotusScript compiler doesn't warn you like in Java - but when the code gets executed, an error is thrown.

When you build a subclass like the ConcreteSubclass, TypeName(Me) doesn't match UCase("AbstractClass") anymore and the constructor New is processed successfully.

If you don't overwrite the abstract method Method in the subclass and call it, the superclass's method is executed and aborts with a corresponding error.

Technical article Development

Sie haben Fragen zu diesem Artikel? Kontaktieren Sie uns gerne: blog@assono.de

Do you want an individual solution? Contact us

More interesting entries

Any questions? Contact us.

If you want to know more about our offers, you can contact us at any time. There are several ways to contact us for a non-binding first consultation.

We don’t sell your data. 100% guaranteed. See: Privacy Policy
assono GmbH

Location Kiel (headquarters)
assono GmbH
Lise-Meitner-Straße 1–7
24223 Schwentinental

Location Hamburg
assono GmbH
Bornkampsweg 58
22761 Hamburg

Phone numbers:
Human resources department: +49 4307 900 407
Marketing department: +49 4307 900 402

E-Mail adresses:
contact@assono.de
bewerbung@assono.de