Abstract type: Difference between revisions
Content added Content deleted
Line 108: | Line 108: | ||
=={{header|Genyris}}== |
=={{header|Genyris}}== |
||
In Genyris by default there are no constructors. In effect all classes are Abstract until they are used to tag an object. |
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 |
<lang python>class AbstractStack()</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. |
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 |
<lang python>class AbstractStack() |
||
def !valid?(object) nil |
def !valid?(object) nil |
||
tag Stack some-object ; always fails |
tag Stack some-object ; always fails |
||
*** Error: class |
*** Error: class AbstractStack 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: |
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 |
<lang python>class StackInterface() |
||
def !valid?(object) |
def !valid?(object) |
||
object |
object |
||
Line 137: | Line 137: | ||
tmp</lang> |
tmp</lang> |
||
Now we instantate a concrete object and validate that it conforms to the Abstract type: |
Now we instantate a concrete object and validate that it conforms to the Abstract type: |
||
<lang python>(XYZstack(!new)) : |
<lang python>(XYZstack(!new)) : StackInterface</lang> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |