Abstract type: Difference between revisions
Content added Content deleted
(Add Skew) |
|||
Line 3,173: | Line 3,173: | ||
END TEXTHASHKEY; |
END TEXTHASHKEY; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Skew}}== |
|||
{{works with|skewc|0.9.19}} |
|||
In Skew, interfaces must be explicitly implemented with `::`. |
|||
<syntaxhighlight lang="skew"> |
|||
@entry |
|||
def main { |
|||
var rgb = Rgb.new(0, 255, 255) |
|||
var hex = Hex.new("00ffff") |
|||
var color Color |
|||
color = hex |
|||
color.print |
|||
color = rgb |
|||
color.print |
|||
(hex as Color).print |
|||
} |
|||
interface Color { |
|||
def toString string |
|||
def print { |
|||
dynamic.console.log(self.toString) |
|||
} |
|||
} |
|||
class Rgb :: Color { |
|||
var r int, g int, b int |
|||
def toString string { return "rgb(\(r), \(g), \(b))" } |
|||
} |
|||
class Hex :: Color { |
|||
var code string |
|||
def toString string { return "#\(code)" } |
|||
} |
|||
</syntaxhighlight> |
|||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
A class is declared abtract by responding to the query <tt>isAbstract</tt> with true, and defining the required protocol for subclasses to raise an error notification. Optionally, instance creation can be blocked (but seldom done, as you will hit a subclassResponsibility anyway soon). Typically, the IDE provides menu functions to generate these definitions automatically (eg. "Insert Abstract Class" in the refactoring submenu of the class browser): |
A class is declared abtract by responding to the query <tt>isAbstract</tt> with true, and defining the required protocol for subclasses to raise an error notification. Optionally, instance creation can be blocked (but seldom done, as you will hit a subclassResponsibility anyway soon). Typically, the IDE provides menu functions to generate these definitions automatically (eg. "Insert Abstract Class" in the refactoring submenu of the class browser): |