Abstract type: Difference between revisions

Line 108:
=={{header|Genyris}}==
In Genyris by default there are no constructors. In effect all classes are Abstract until they are used to tag an object.
<lang python>class StackAbstractStack()</lang>
There is no constructor for this class. To prevent the class ever being associated with an instance it suffices to force the validator to fail.
<lang python>class StackAbstractStack()
def !valid?(object) nil
 
tag Stack some-object ; always fails
*** Error: class StackAbstractStack validator error for object ...</lang>
 
However this is not much use if we want to use an abstract class to define an interface. Here is a quasi-abstract class which can be used to tag objects if they conform to the class's membership expectations. In this case it wants two methods, !enstack and !destack:
<lang python>class AbstractStackStackInterface()
def !valid?(object)
object
Line 137:
tmp</lang>
Now we instantate a concrete object and validate that it conforms to the Abstract type:
<lang python>(XYZstack(!new)) : AbstractStackStackInterface</lang>
 
=={{header|Haskell}}==
Anonymous user