September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,7 +1,7 @@
|
|||
public abstract class Abs {
|
||||
abstract public int method1(double value);
|
||||
abstract protected int method2(String name);
|
||||
int add(int a, int b){
|
||||
return a+b;
|
||||
}
|
||||
public abstract int method1(double value);
|
||||
protected abstract int method2(String name);
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
public interface Inter {
|
||||
int method1(double value);
|
||||
int method2(String name);
|
||||
int add(int a, int b);
|
||||
int method1(double value);
|
||||
int method2(String name);
|
||||
int add(int a, int b);
|
||||
}
|
||||
|
|
|
|||
55
Task/Abstract-type/Kotlin/abstract-type.kotlin
Normal file
55
Task/Abstract-type/Kotlin/abstract-type.kotlin
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
// version 1.1
|
||||
|
||||
interface Announcer {
|
||||
fun announceType()
|
||||
|
||||
// interface can contain non-abstract members but cannot store state
|
||||
fun announceName() {
|
||||
println("I don't have a name")
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Animal: Announcer {
|
||||
abstract fun makeNoise()
|
||||
|
||||
// abstract class can contain non-abstract members
|
||||
override fun announceType() {
|
||||
println("I am an Animal")
|
||||
}
|
||||
}
|
||||
|
||||
class Dog(private val name: String) : Animal() {
|
||||
override fun makeNoise() {
|
||||
println("Woof!")
|
||||
}
|
||||
|
||||
override fun announceName() {
|
||||
println("I'm called $name")
|
||||
}
|
||||
}
|
||||
|
||||
class Cat: Animal() {
|
||||
override fun makeNoise() {
|
||||
println("Meow!")
|
||||
}
|
||||
|
||||
override fun announceType() {
|
||||
println("I am a Cat")
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val d = Dog("Fido")
|
||||
with(d) {
|
||||
makeNoise()
|
||||
announceType() // inherits Animal's implementation
|
||||
announceName()
|
||||
}
|
||||
println()
|
||||
val c = Cat()
|
||||
with(c) {
|
||||
makeNoise()
|
||||
announceType()
|
||||
announceName() // inherits Announcer's implementation
|
||||
}
|
||||
}
|
||||
3
Task/Abstract-type/MATLAB/abstract-type-1.m
Normal file
3
Task/Abstract-type/MATLAB/abstract-type-1.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
classdef (Abstract) AbsClass
|
||||
...
|
||||
end
|
||||
3
Task/Abstract-type/MATLAB/abstract-type-2.m
Normal file
3
Task/Abstract-type/MATLAB/abstract-type-2.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
methods (Abstract)
|
||||
abstMethod(obj)
|
||||
end
|
||||
3
Task/Abstract-type/MATLAB/abstract-type-3.m
Normal file
3
Task/Abstract-type/MATLAB/abstract-type-3.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
properties (Abstract)
|
||||
AbsProp
|
||||
end
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
type
|
||||
Comparable = generic x, y
|
||||
Comparable = concept x, y
|
||||
(x < y) is bool
|
||||
|
||||
Container[T] = generic c
|
||||
c.len is ordinal
|
||||
items(c) is iterator
|
||||
for value in c:
|
||||
type(value) is T
|
||||
Stack[T] = concept s, var v
|
||||
s.pop() is T
|
||||
v.push(T)
|
||||
|
||||
s.len is Ordinal
|
||||
|
||||
for value in s:
|
||||
value is T
|
||||
|
|
|
|||
60
Task/Abstract-type/OoRexx/abstract-type-1.rexx
Normal file
60
Task/Abstract-type/OoRexx/abstract-type-1.rexx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
-- Example showing a class that defines an interface in ooRexx
|
||||
-- shape is the interface class that defines the methods a shape instance
|
||||
-- is expected to implement as abstract methods. Instances of the shape
|
||||
-- class need not directly subclass the interface, but can use multiple
|
||||
-- inheritance to mark itself as implementing the interface.
|
||||
|
||||
r=.rectangle~new(5,2)
|
||||
say r
|
||||
-- check for instance of
|
||||
if r~isa(.shape) then say "a" r~name "is a shape"
|
||||
say "r~area:" r~area
|
||||
say
|
||||
|
||||
c=.circle~new(2)
|
||||
say c
|
||||
-- check for instance of shape works even if inherited
|
||||
if c~isa(.shape) then say "a" c~name "is a shape"
|
||||
say "c~area:" c~area
|
||||
say
|
||||
|
||||
-- a mixin is still a class and can be instantiated. The abstract methods
|
||||
-- will give an error if invoked
|
||||
g=.shape~new
|
||||
say g
|
||||
say g~name
|
||||
say "g~area:" g~area -- invoking abstract method results in a runtime error.
|
||||
|
||||
-- the "MIXINCLASS" tag makes this avaiable for multiple inhertance
|
||||
::class shape MIXINCLASS Object
|
||||
::method area abstract
|
||||
::method name abstract
|
||||
|
||||
-- directly subclassing the the interface
|
||||
::class rectangle subclass shape
|
||||
|
||||
::method init
|
||||
expose length width
|
||||
use strict arg length=0, width=0
|
||||
|
||||
::method area
|
||||
expose length width
|
||||
return length*width
|
||||
|
||||
::method name
|
||||
return "Rectangle"
|
||||
|
||||
-- inherits the shape methods
|
||||
::class circle subclass object inherit shape
|
||||
|
||||
::method init
|
||||
expose radius
|
||||
use strict arg radius=0
|
||||
|
||||
::method area
|
||||
expose radius
|
||||
numeric digits 20
|
||||
return radius*radius*3.14159265358979323846
|
||||
|
||||
::method name
|
||||
return "Circle"
|
||||
51
Task/Abstract-type/OoRexx/abstract-type-2.rexx
Normal file
51
Task/Abstract-type/OoRexx/abstract-type-2.rexx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
-- Example showing an abstract type in ooRexx
|
||||
-- shape is the abstract class that defines the abstract method area
|
||||
-- which is then implemented by its two subclasses, rectangle and circle
|
||||
-- name is the method inherited by the subclasses.
|
||||
-- author: Rony G. Flatscher, 2012-05-26
|
||||
-- changed/edited: Walter Pachl, 2012-05-28 28
|
||||
-- highlighting: to come
|
||||
|
||||
r=.rectangle~new(5,2)
|
||||
say r
|
||||
say r~name
|
||||
say "r~area:" r~area
|
||||
say
|
||||
|
||||
c=.circle~new(2)
|
||||
say c
|
||||
say c~name
|
||||
say "c~area:" c~area
|
||||
say
|
||||
|
||||
g=.shape~new
|
||||
say g
|
||||
say g~name
|
||||
say "g~area:" g~area -- invoking abstract method results in a runtime error.
|
||||
|
||||
::class shape
|
||||
::method area abstract
|
||||
::method name
|
||||
return "self~class~id:" self~class~id
|
||||
|
||||
|
||||
::class rectangle subclass shape
|
||||
|
||||
::method init
|
||||
expose length width
|
||||
use strict arg length=0, width=0
|
||||
|
||||
::method area
|
||||
expose length width
|
||||
return length*width
|
||||
|
||||
::class circle subclass shape
|
||||
|
||||
::method init
|
||||
expose radius
|
||||
use strict arg radius=0
|
||||
|
||||
::method area
|
||||
expose radius
|
||||
numeric digits 20
|
||||
return radius*radius*3.14159265358979323846
|
||||
9
Task/Abstract-type/Simula/abstract-type-1.simula
Normal file
9
Task/Abstract-type/Simula/abstract-type-1.simula
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
! ABSTRACT HASH KEY TYPE ;
|
||||
LISTVAL CLASS HASHKEY;
|
||||
VIRTUAL:
|
||||
PROCEDURE HASH IS
|
||||
INTEGER PROCEDURE HASH;;
|
||||
PROCEDURE EQUALTO IS
|
||||
BOOLEAN PROCEDURE EQUALTO(K); REF(HASHKEY) K;;
|
||||
BEGIN
|
||||
END HASHKEY;
|
||||
20
Task/Abstract-type/Simula/abstract-type-2.simula
Normal file
20
Task/Abstract-type/Simula/abstract-type-2.simula
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
! COMMON HASH KEY TYPE IS TEXT ;
|
||||
HASHKEY CLASS TEXTHASHKEY(T); VALUE T; TEXT T;
|
||||
BEGIN
|
||||
INTEGER PROCEDURE HASH;
|
||||
BEGIN
|
||||
INTEGER I;
|
||||
T.SETPOS(1);
|
||||
WHILE T.MORE DO
|
||||
I := 31*I+RANK(T.GETCHAR);
|
||||
IF DEBUG THEN BEGIN
|
||||
OUTIMAGE;
|
||||
OUTTEXT("HASHMAPS.TEXTHASHKEY.HASH=");
|
||||
OUTINT(I,0);
|
||||
OUTIMAGE;
|
||||
END;
|
||||
HASH := I;
|
||||
END HASH;
|
||||
BOOLEAN PROCEDURE EQUALTO(K); REF(HASHKEY) K;
|
||||
EQUALTO := T = K QUA TEXTHASHKEY.T;
|
||||
END TEXTHASHKEY;
|
||||
21
Task/Abstract-type/Zkl/abstract-type-1.zkl
Normal file
21
Task/Abstract-type/Zkl/abstract-type-1.zkl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class Stream{ // Mostly virtural base class
|
||||
var [proxy protected]
|
||||
isBroken = fcn { _broken.isSet() },
|
||||
isClosed = fcn { return(_closed.isSet() or _broken.isSet()); };
|
||||
fcn init{
|
||||
var [protected]
|
||||
_closed = Atomic.Bool(True),
|
||||
_broken = Atomic.Bool(False),
|
||||
whyBroken = Void;
|
||||
}
|
||||
fcn clear { _closed.clear(); _broken.clear(); return(self.topdog); }
|
||||
fcn open { return(topdog.init(vm.pasteArgs())); }
|
||||
fcn toStream { return(self); }
|
||||
fcn close { _closed.set(); return(self.topdog); }
|
||||
fcn flush { return(self.topdog); }
|
||||
fcn read { throw(Exception.TheEnd); } // destructive or advance
|
||||
fcn readln { throw(Exception.TheEnd); }
|
||||
fcn write(x) { return(self.topdog); }
|
||||
fcn writeln(x) { return(self.topdog); }
|
||||
fcn walker { return((0).walker(*,wap((self.topdog.read.fpM(""))))); }
|
||||
}
|
||||
5
Task/Abstract-type/Zkl/abstract-type-2.zkl
Normal file
5
Task/Abstract-type/Zkl/abstract-type-2.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class DevNull(Stream){
|
||||
var [const] fileName = "DevNull"; // compatibility with File
|
||||
fcn init { Stream.init() }
|
||||
fcn write(x) { return(0); }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue