langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
72
Task/Abstract-type/NetRexx/abstract-type.netrexx
Normal file
72
Task/Abstract-type/NetRexx/abstract-type.netrexx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols binary
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
class RCAbstractType public final
|
||||
|
||||
method main(args = String[]) public constant
|
||||
|
||||
say ' Testing' RCAbstractType.class.getSimpleName
|
||||
say ' Creating an object of type:' Concrete.class.getSimpleName
|
||||
conk = Concrete()
|
||||
say 'getClassName:'.right(20) conk.getClassName
|
||||
say 'getIfaceName:'.right(20) conk.getIfaceName
|
||||
say 'mustImplement:'.right(20) conk.mustImplement
|
||||
say 'canOverride1:'.right(20) conk.canOverride1
|
||||
say 'canOverride2:'.right(20) conk.canOverride2
|
||||
say 'callOverridden2:'.right(20) conk.callOverridden2
|
||||
|
||||
return
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
class RCAbstractType.Iface interface
|
||||
|
||||
ifaceName = RCAbstractType.Iface.class.getSimpleName
|
||||
|
||||
method getIfaceName() public returns String
|
||||
method canOverride1() public returns String
|
||||
method canOverride2() public returns String
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
class RCAbstractType.Abstraction abstract implements RCAbstractType.Iface
|
||||
|
||||
properties inheritable
|
||||
className = String
|
||||
|
||||
method Abstraction() public
|
||||
setClassName(this.getClass.getSimpleName)
|
||||
return
|
||||
|
||||
method mustImplement() public abstract returns String
|
||||
|
||||
method getClassName() public returns String
|
||||
return className
|
||||
|
||||
method setClassName(nm = String) public
|
||||
className = nm
|
||||
return
|
||||
|
||||
method getIfaceName() public returns String
|
||||
return RCAbstractType.Iface.ifaceName
|
||||
|
||||
method canOverride1() public returns String
|
||||
return 'In' RCAbstractType.Abstraction.class.getSimpleName'.canOverride1'
|
||||
|
||||
method canOverride2() public returns String
|
||||
return 'In' RCAbstractType.Abstraction.class.getSimpleName'.canOverride2'
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
class RCAbstractType.Concrete extends RCAbstractType.Abstraction
|
||||
|
||||
method Concrete() public
|
||||
super()
|
||||
return
|
||||
|
||||
method mustImplement() public returns String
|
||||
return 'In' RCAbstractType.Concrete.class.getSimpleName'.mustImplement'
|
||||
|
||||
method canOverride2() public returns String
|
||||
return 'In' RCAbstractType.Concrete.class.getSimpleName'.canOverride2'
|
||||
|
||||
method callOverridden2() public returns String
|
||||
return super.canOverride2
|
||||
46
Task/Abstract-type/NewLISP/abstract-type.newlisp
Normal file
46
Task/Abstract-type/NewLISP/abstract-type.newlisp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
; file: abstract.lsp
|
||||
; url: http://rosettacode.org/wiki/Abstract_type
|
||||
; author: oofoe 2012-01-28
|
||||
|
||||
; Abstract Shape Class
|
||||
|
||||
(new Class 'Shape) ; Derive new class.
|
||||
|
||||
(define (Shape:Shape ; Shape constructor.
|
||||
(pen "X")) ; Default value.
|
||||
(list (context) ; Assemble data packet.
|
||||
(list 'pen pen)
|
||||
(list 'size (args))))
|
||||
|
||||
(define (Shape:line x) ; Print out row with 'pen' character.
|
||||
(dotimes (i x)
|
||||
(print (lookup 'pen (self))))
|
||||
(println))
|
||||
|
||||
(define (Shape:draw)) ; Placeholder, does nothing.
|
||||
|
||||
; Derived Objects
|
||||
|
||||
(new Shape 'Box)
|
||||
|
||||
(define (Box:draw) ; Override base draw method.
|
||||
(let ((s (lookup 'size (self))))
|
||||
(dotimes (i (s 0)) (:line (self) (s 0)))))
|
||||
|
||||
(new Shape 'Rectangle)
|
||||
|
||||
(define (Rectangle:draw)
|
||||
(let ((size (lookup 'size (self))))
|
||||
(dotimes (i (size 1)) (:line (self) (size 0)))))
|
||||
|
||||
; Demonstration
|
||||
|
||||
(:draw (Shape)) ; Nothing happens.
|
||||
|
||||
(println "A box:")
|
||||
(:draw (Box "O" 5)) ; Create Box object and call draw method.
|
||||
|
||||
(println "\nA rectangle:")
|
||||
(:draw (Rectangle "R" 32 4))
|
||||
|
||||
(exit)
|
||||
4
Task/Abstract-type/OCaml/abstract-type-1.ocaml
Normal file
4
Task/Abstract-type/OCaml/abstract-type-1.ocaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class virtual foo =
|
||||
object
|
||||
method virtual bar : int
|
||||
end
|
||||
1
Task/Abstract-type/OCaml/abstract-type-2.ocaml
Normal file
1
Task/Abstract-type/OCaml/abstract-type-2.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
type t
|
||||
5
Task/Abstract-type/OCaml/abstract-type-3.ocaml
Normal file
5
Task/Abstract-type/OCaml/abstract-type-3.ocaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module Foo : sig
|
||||
type t
|
||||
end = struct
|
||||
type t = int * int
|
||||
end
|
||||
5
Task/Abstract-type/OCaml/abstract-type-4.ocaml
Normal file
5
Task/Abstract-type/OCaml/abstract-type-4.ocaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
type u
|
||||
type v
|
||||
type 'a t
|
||||
type ut = u t
|
||||
type vt = v t
|
||||
7
Task/Abstract-type/Objeck/abstract-type.objeck
Normal file
7
Task/Abstract-type/Objeck/abstract-type.objeck
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class ClassA {
|
||||
method : virtual : public : MethodA() ~ Int;
|
||||
|
||||
method : public : MethodA() ~ Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
23
Task/Abstract-type/Oz/abstract-type.oz
Normal file
23
Task/Abstract-type/Oz/abstract-type.oz
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
declare
|
||||
class BaseQueue
|
||||
attr
|
||||
contents:nil
|
||||
|
||||
meth init
|
||||
raise notImplemented(self init) end
|
||||
end
|
||||
|
||||
meth enqueue(Item)
|
||||
raise notImplemented(self enqueue) end
|
||||
end
|
||||
|
||||
meth dequeue(?Item)
|
||||
raise notImplemented(self dequeue) end
|
||||
end
|
||||
|
||||
meth printContents
|
||||
{ForAll @contents Show}
|
||||
end
|
||||
end
|
||||
|
||||
Queue = {New BaseQueue init} %% throws
|
||||
23
Task/Abstract-type/Perl-6/abstract-type.pl6
Normal file
23
Task/Abstract-type/Perl-6/abstract-type.pl6
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use v6;
|
||||
|
||||
role A {
|
||||
# must be filled in by the class it is composed into
|
||||
method abstract() { ... };
|
||||
|
||||
# can be overridden in the class, but that's not mandatory
|
||||
method concrete() { say '# 42' };
|
||||
}
|
||||
|
||||
class SomeClass does A {
|
||||
method abstract() {
|
||||
say "# made concrete in class"
|
||||
}
|
||||
}
|
||||
|
||||
my $obj = SomeClass.new;
|
||||
$obj.abstract();
|
||||
$obj.concrete();
|
||||
|
||||
# output:
|
||||
# made concrete in class
|
||||
# 42
|
||||
46
Task/Abstract-type/REBOL/abstract-type.rebol
Normal file
46
Task/Abstract-type/REBOL/abstract-type.rebol
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
REBOL [
|
||||
Title: "Abstract Type"
|
||||
Author: oofoe
|
||||
Date: 2009-12-05
|
||||
URL: http://rosettacode.org/wiki/Abstract_type
|
||||
]
|
||||
|
||||
; The "shape" class is an abstract class -- it defines the "pen"
|
||||
; property and "line" method, but "size" and "draw" are undefined and
|
||||
; unimplemented.
|
||||
|
||||
shape: make object! [
|
||||
pen: "X"
|
||||
size: none
|
||||
|
||||
line: func [count][loop count [prin self/pen] prin crlf]
|
||||
draw: does [none]
|
||||
]
|
||||
|
||||
; The "box" class inherits from "shape" and provides the missing
|
||||
; information for drawing boxes.
|
||||
|
||||
box: make shape [
|
||||
size: 10
|
||||
draw: does [loop self/size [line self/size]]
|
||||
]
|
||||
|
||||
; "rectangle" also inherits from "shape", but handles the
|
||||
; implementation very differently.
|
||||
|
||||
rectangle: make shape [
|
||||
size: 20x10
|
||||
draw: does [loop self/size/y [line self/size/x]]
|
||||
]
|
||||
|
||||
; Unlike some languages discussed, REBOL has absolutely no qualms
|
||||
; about instantiating an "abstract" class -- that's how I created the
|
||||
; derived classes of "rectangle" and "box", after all.
|
||||
|
||||
s: make shape [] s/draw ; Nothing happens.
|
||||
|
||||
print "A box:"
|
||||
b: make box [pen: "O" size: 5] b/draw
|
||||
|
||||
print [crlf "A rectangle:"]
|
||||
r: make rectangle [size: 32x5] r/draw
|
||||
17
Task/Abstract-type/Visual-Basic-.NET/abstract-type-1.visual
Normal file
17
Task/Abstract-type/Visual-Basic-.NET/abstract-type-1.visual
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
MustInherit Class Base
|
||||
|
||||
Protected Sub New()
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub StandardMethod()
|
||||
'code
|
||||
End Sub
|
||||
|
||||
Public Overridable Sub Method_Can_Be_Replaced()
|
||||
'code
|
||||
End Sub
|
||||
|
||||
Public MustOverride Sub Method_Must_Be_Replaced()
|
||||
|
||||
End Class
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Interface IBase
|
||||
Sub Method_Must_Be_Implemented()
|
||||
End Interface
|
||||
Loading…
Add table
Add a link
Reference in a new issue