Anonymous user
Abstract type: Difference between revisions
added Caché ObjectScript
(Updated Julia) |
(added Caché ObjectScript) |
||
Line 379:
};</lang>
Because C++ allows multiple inheritance of classes, no distinction is made between interfaces and abstract classes.
=={{header|Caché ObjectScript}}==
In Caché, abstract and data type classes cannot be instantiated directly - there must be a 'concrete subclass' that extends them as well as the '%RegisteredObject' class in order to instantiate an object, see example below.
<lang cos>Class Abstract.Class.Shape [ Abstract ]
{
Parameter SHAPE = 1;
Property Name As %String;
Method Description() {}
}
Class Abstract.Class.Square Extends (%RegisteredObject, Shape)
{
Method Description()
{
Write "SHAPE=", ..#SHAPE, !
Write ..%ClassName()_$Case(..%Extends(..%PackageName()_".Shape"), 1: " is a ", : " is not a ")_"shape"
}
}</lang>
Data type classes differ because they cannot contain properties, see example below.
<lang cos>Class Abstract.DataType.Shape [ ClassType = datatype ]
{
Parameter SHAPE = 1;
Method Description() {}
}
Class Abstract.DataType.Square Extends (%RegisteredObject, Shape)
{
Method Description()
{
Write "SHAPE=", ..#SHAPE, !
Write ..%ClassName()_$Case(..%Extends(..%PackageName()_".Shape"), 1: " is a ", : " is not a ")_"shape"
}
}</lang>
Both class types can contain implementation code. Caché allows multiple inheritance of classes, so no distinction is made between abstract classes and interfaces.
{{out|Examples}}
<pre>
USER>Do ##class(Abstract.Class.Square).%New().Description()
SHAPE=1
Square is a shape
USER>Do ##class(Abstract.DataType.Square).%New().Description()
SHAPE=1
Square is a shape
</pre>
=={{header|Clojure}}==
|