Add all the A tasks
This commit is contained in:
parent
2dd7375f96
commit
051504d65b
1608 changed files with 18584 additions and 0 deletions
11
Task/Abstract-type/0DESCRIPTION
Normal file
11
Task/Abstract-type/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
'''Abstract type''' is a type without instances or without definition.
|
||||
|
||||
For example in [[object-oriented programming]] using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract types without any implementation are called '''interfaces'''. In the languages that do not support multiple [[inheritance]] ([[Ada]], [[Java]]), classes can, nonetheless, inherit from multiple interfaces. The languages with multiple inheritance (like [[C++]]) usually make no distinction between partially implementable abstract types and interfaces. Because the abstract type's implementation is incomplete, [[object-oriented programming | OO]] languages normally prevent instantiation from them (instantiation must derived from one of their descendant classes).
|
||||
|
||||
The term '''abstract datatype''' also may denote a type, with an implementation provided by the programmer rather than directly by the language (a '''built-in''' or an inferred type). Here the word ''abstract'' means that the implementation is abstracted away, irrelevant for the user of the type. Such implementation can and should be hidden if the language supports separation of implementation and specification. This hides complexity while allowing the implementation to change without repercussions on the usage. The corresponding software design practice is said to follow the [[wp:Information_hiding|information hiding principle]].
|
||||
|
||||
It is important not to confuse this ''abstractness'' (of implementation) with one of the '''abstract type'''. The latter is abstract in the sense that the set of its values is empty. In the sense of implementation abstracted away, all user-defined types are abstract.
|
||||
|
||||
In some languages, like for example in Objective Caml which is strongly statically typed, it is also possible to have '''abstract types''' that are not OO related and are not an abstractness too. These are ''pure abstract types'' without any definition even in the implementation and can be used for example for the type algebra, or for some consistence of the type inference. For example in this area, an abstract type can be used as a phantom type to augment another type as its parameter. <!-- An OCaml Guru would explain this better than me, a poor beginner... -->
|
||||
|
||||
'''Task''': show how an abstract type can be declared in the language. If the language makes a distinction between interfaces and partially implemented types illustrate both.
|
||||
5
Task/Abstract-type/1META.yaml
Normal file
5
Task/Abstract-type/1META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Object oriented
|
||||
- Type System
|
||||
note: Basic language learning
|
||||
13
Task/Abstract-type/ABAP/abstract-type-1.abap
Normal file
13
Task/Abstract-type/ABAP/abstract-type-1.abap
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class abs definition abstract.
|
||||
public section.
|
||||
methods method1 abstract importing iv_value type f exporting ev_ret type i.
|
||||
protected section.
|
||||
methods method2 abstract importing iv_name type string exporting ev_ret type i.
|
||||
methods add importing iv_a type i iv_b type i exporting ev_ret type i.
|
||||
endclass.
|
||||
|
||||
class abs implementation.
|
||||
method add.
|
||||
ev_ret = iv_a + iv_b.
|
||||
endmethod.
|
||||
endclass.
|
||||
5
Task/Abstract-type/ABAP/abstract-type-2.abap
Normal file
5
Task/Abstract-type/ABAP/abstract-type-2.abap
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
interface inter.
|
||||
methods: method1 importing iv_value type f exporting ev_ret type i,
|
||||
method2 importing iv_name type string exporting ev_ret type i,
|
||||
add importing iv_a type i iv_b type i exporting ev_ret type i.
|
||||
endinterface.
|
||||
8
Task/Abstract-type/ActionScript/abstract-type.as
Normal file
8
Task/Abstract-type/ActionScript/abstract-type.as
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package
|
||||
{
|
||||
public interface IInterface
|
||||
{
|
||||
function method1():void;
|
||||
function method2(arg1:Array, arg2:Boolean):uint;
|
||||
}
|
||||
}
|
||||
3
Task/Abstract-type/Ada/abstract-type-1.ada
Normal file
3
Task/Abstract-type/Ada/abstract-type-1.ada
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
type Queue is limited interface;
|
||||
procedure Enqueue (Lounge : in out Queue; Item : in out Element) is abstract;
|
||||
procedure Dequeue (Lounge : in out Queue; Item : in out Element) is abstract;
|
||||
2
Task/Abstract-type/Ada/abstract-type-2.ada
Normal file
2
Task/Abstract-type/Ada/abstract-type-2.ada
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
type Scheduler is task interface;
|
||||
procedure Plan (Manager : in out Scheduler; Activity : in out Job) is abstract;
|
||||
10
Task/Abstract-type/Ada/abstract-type-3.ada
Normal file
10
Task/Abstract-type/Ada/abstract-type-3.ada
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
with Ada.Finalization;
|
||||
...
|
||||
type Node is abstract new Ada.Finalization.Limited_Controlled and Queue with record
|
||||
Previous : not null access Node'Class := Node'Unchecked_Access;
|
||||
Next : not null access Node'Class := Node'Unchecked_Access;
|
||||
end record;
|
||||
overriding procedure Finalize (X : in out Node); -- Removes the node from its list if any
|
||||
overriding procedure Dequeue (Lounge : in out Node; Item : in out Element);
|
||||
overriding procedure Enqueue (Lounge : in out Node; Item : in out Element);
|
||||
procedure Process (X : in out Node) is abstract; -- To be implemented
|
||||
53
Task/Abstract-type/Agda/abstract-type.agda
Normal file
53
Task/Abstract-type/Agda/abstract-type.agda
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
module AbstractInterfaceExample where
|
||||
|
||||
open import Function
|
||||
open import Data.Bool
|
||||
open import Data.String
|
||||
|
||||
-- * One-parameter interface for the type `a' with only one method.
|
||||
|
||||
record VoiceInterface (a : Set) : Set where
|
||||
constructor voice-interface
|
||||
field say-method-of : a → String
|
||||
|
||||
open VoiceInterface
|
||||
|
||||
-- * An overloaded method.
|
||||
|
||||
say : {a : Set} → ⦃ _ : VoiceInterface a ⦄ → a → String
|
||||
say ⦃ instance ⦄ = say-method-of instance
|
||||
|
||||
-- * Some data types.
|
||||
|
||||
data Cat : Set where
|
||||
cat : Bool → Cat
|
||||
|
||||
crazy! = true
|
||||
plain-cat = false
|
||||
|
||||
-- | This cat is crazy?
|
||||
crazy? : Cat → Bool
|
||||
crazy? (cat x) = x
|
||||
|
||||
-- | A 'plain' dog.
|
||||
data Dog : Set where
|
||||
dog : Dog
|
||||
|
||||
-- * Implementation of the interface (and method).
|
||||
|
||||
instance-for-cat : VoiceInterface Cat
|
||||
instance-for-cat = voice-interface case where
|
||||
case : Cat → String
|
||||
case x with crazy? x
|
||||
... | true = "meeeoooowwwww!!!"
|
||||
... | false = "meow!"
|
||||
|
||||
instance-for-dog : VoiceInterface Dog
|
||||
instance-for-dog = voice-interface $ const "woof!"
|
||||
|
||||
-- * and then:
|
||||
--
|
||||
-- say dog => "woof!"
|
||||
-- say (cat crazy!) => "meeeoooowwwww!!!"
|
||||
-- say (cat plain-cat) => "meow!"
|
||||
--
|
||||
5
Task/Abstract-type/Aikido/abstract-type-1.aikido
Normal file
5
Task/Abstract-type/Aikido/abstract-type-1.aikido
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class Abs {
|
||||
public function method1...
|
||||
public function method2...
|
||||
|
||||
}
|
||||
5
Task/Abstract-type/Aikido/abstract-type-2.aikido
Normal file
5
Task/Abstract-type/Aikido/abstract-type-2.aikido
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
interface Inter {
|
||||
function isFatal : integer
|
||||
function operate (para : integer = 0)
|
||||
operator -> (stream, isout)
|
||||
}
|
||||
38
Task/Abstract-type/Argile/abstract-type.argile
Normal file
38
Task/Abstract-type/Argile/abstract-type.argile
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use std
|
||||
|
||||
(: abstract class :)
|
||||
|
||||
class Abs
|
||||
text name
|
||||
AbsIface iface
|
||||
|
||||
class AbsIface
|
||||
function(Abs)(int)->int method
|
||||
|
||||
let Abs_Iface = Cdata AbsIface@ {.method = nil}
|
||||
|
||||
.: new Abs :. -> Abs {let a = new(Abs); a.iface = Abs_Iface; a}
|
||||
|
||||
=: <Abs self>.method <int i> := -> int
|
||||
(self.iface.method is nil) ? 0 , (call self.iface.method with self i)
|
||||
|
||||
(: implementation :)
|
||||
|
||||
class Sub <- Abs { int value }
|
||||
|
||||
let Sub_Iface = Cdata AbsIface@ {.method = (code of (nil the Sub).method 0)}
|
||||
|
||||
.: new Sub (<int value = -1>) :. -> Sub
|
||||
let s = new (Sub)
|
||||
s.iface = Sub_Iface
|
||||
s.value = value
|
||||
s
|
||||
|
||||
.: <Sub this>.method <int i> :. -> int {this.value + i}
|
||||
|
||||
(: example use :)
|
||||
|
||||
.:foobar<Abs a>:. {print a.method 12 ; del a}
|
||||
foobar (new Sub 34) (: prints 46 :)
|
||||
foobar (new Sub) (: prints 11 :)
|
||||
foobar (new Abs) (: prints 0 :)
|
||||
28
Task/Abstract-type/AutoHotkey/abstract-type.ahk
Normal file
28
Task/Abstract-type/AutoHotkey/abstract-type.ahk
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
color(r, g, b){
|
||||
static color
|
||||
If !color
|
||||
color := Object("base", Object("R", r, "G", g, "B", b
|
||||
,"GetRGB", "Color_GetRGB"))
|
||||
return Object("base", Color)
|
||||
}
|
||||
Color_GetRGB(clr) {
|
||||
return "not implemented"
|
||||
}
|
||||
|
||||
waterColor(r, g, b){
|
||||
static waterColor
|
||||
If !waterColor
|
||||
waterColor := Object("base", color(r, g, b),"GetRGB", "WaterColor_GetRGB")
|
||||
return Object("base", WaterColor)
|
||||
}
|
||||
|
||||
WaterColor_GetRGB(clr){
|
||||
return clr.R << 16 | clr.G << 8 | clr.B
|
||||
}
|
||||
|
||||
test:
|
||||
blue := color(0, 0, 255)
|
||||
msgbox % blue.GetRGB() ; displays "not implemented"
|
||||
blue := waterColor(0, 0, 255)
|
||||
msgbox % blue.GetRGB() ; displays 255
|
||||
return
|
||||
33
Task/Abstract-type/C/abstract-type-1.c
Normal file
33
Task/Abstract-type/C/abstract-type-1.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef INTERFACE_ABS
|
||||
#define INTERFACE_ABS
|
||||
|
||||
typedef struct sAbstractCls *AbsCls;
|
||||
|
||||
typedef struct sAbstractMethods {
|
||||
int (*method1)(AbsCls c, int a);
|
||||
const char *(*method2)(AbsCls c, int b);
|
||||
void (*method3)(AbsCls c, double d);
|
||||
} *AbstractMethods, sAbsMethods;
|
||||
|
||||
struct sAbstractCls {
|
||||
AbstractMethods klass;
|
||||
void *instData;
|
||||
};
|
||||
|
||||
#define ABSTRACT_METHODS( cName, m1, m2, m3 ) \
|
||||
static sAbsMethods cName ## _Iface = { &m1, &m2, &m3 }; \
|
||||
AbsCls cName ## _Instance( void *clInst) { \
|
||||
AbsCls ac = malloc(sizeof(struct sAbstractCls)); \
|
||||
if (ac) { \
|
||||
ac->klass = &cName ## _Iface; \
|
||||
ac->instData = clInst; \
|
||||
}\
|
||||
return ac; }
|
||||
|
||||
#define Abs_Method1( c, a) (c)->klass->method1(c, a)
|
||||
#define Abs_Method2( c, b) (c)->klass->method2(c, b)
|
||||
#define Abs_Method3( c, d) (c)->klass->method3(c, d)
|
||||
#define Abs_Free(c) \
|
||||
do { if (c) { free((c)->instData); free(c); } } while(0);
|
||||
|
||||
#endif
|
||||
9
Task/Abstract-type/C/abstract-type-2.c
Normal file
9
Task/Abstract-type/C/abstract-type-2.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef SILLY_H
|
||||
#define SILLY_H
|
||||
#include intefaceAbs.h
|
||||
|
||||
typedef struct sillyStruct *Silly;
|
||||
extern Silly NewSilly( double, const char *);
|
||||
extern AbsCls Silly_Instance(void *);
|
||||
|
||||
#endif
|
||||
42
Task/Abstract-type/C/abstract-type-3.c
Normal file
42
Task/Abstract-type/C/abstract-type-3.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "silly.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct sillyStruct {
|
||||
double v1;
|
||||
char str[32];
|
||||
};
|
||||
|
||||
Silly NewSilly(double vInit, const char *strInit)
|
||||
{
|
||||
Silly sily = malloc(sizeof( struct sillyStruct ));
|
||||
sily->v1 = vInit;
|
||||
sily->str[0] = '\0';
|
||||
strncat(sily->str, strInit, 31);
|
||||
return sily;
|
||||
}
|
||||
|
||||
static
|
||||
int MyMethod1( AbsCls c, int a)
|
||||
{
|
||||
Silly s = (Silly)(c->instData);
|
||||
return a+strlen(s->str);
|
||||
}
|
||||
|
||||
static
|
||||
const char *MyMethod2(AbsCls c, int b)
|
||||
{
|
||||
Silly s = (Silly)(c->instData);
|
||||
sprintf(s->str, "%d", b);
|
||||
return s->str;
|
||||
}
|
||||
|
||||
static
|
||||
void MyMethod3(AbsCls c, double d)
|
||||
{
|
||||
Silly s = (Silly)(c->instData);
|
||||
printf("InMyMethod3, %f\n",s->v1 * d);
|
||||
}
|
||||
|
||||
ABSTRACT_METHODS( Silly, MyMethod1, MyMethod2, MyMethod3)
|
||||
13
Task/Abstract-type/C/abstract-type-4.c
Normal file
13
Task/Abstract-type/C/abstract-type-4.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include "silly.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
AbsCls abster = Silly_Instance(NewSilly( 10.1, "Green Tomato"));
|
||||
|
||||
printf("AbsMethod1: %d\n", Abs_Method1(abster, 5));
|
||||
printf("AbsMethod2: %s\n", Abs_Method2(abster, 4));
|
||||
Abs_Method3(abster, 21.55);
|
||||
Abs_Free(abster);
|
||||
return 0;
|
||||
}
|
||||
1
Task/Abstract-type/Clojure/abstract-type.clj
Normal file
1
Task/Abstract-type/Clojure/abstract-type.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(defprotocol Foo (foo [this]))
|
||||
17
Task/Abstract-type/Eiffel/abstract-type.e
Normal file
17
Task/Abstract-type/Eiffel/abstract-type.e
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
deferred class
|
||||
AN_ABSTRACT_CLASS
|
||||
|
||||
feature
|
||||
|
||||
a_deferred_feature
|
||||
-- a feature whose implementation is left to a descendent
|
||||
deferred
|
||||
end
|
||||
|
||||
an_effective_feature: STRING
|
||||
-- deferred (abstract) classes may still include effective features
|
||||
do
|
||||
Result := "I am implemented!"
|
||||
end
|
||||
|
||||
end
|
||||
25
Task/Abstract-type/Forth/abstract-type.fth
Normal file
25
Task/Abstract-type/Forth/abstract-type.fth
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
include 4pp/lib/foos.4pp
|
||||
|
||||
:: X()
|
||||
class
|
||||
method: method1
|
||||
method: method2
|
||||
end-class {
|
||||
:method { ." Method 1 in X" cr } ; defines method1
|
||||
}
|
||||
;
|
||||
|
||||
:: Y()
|
||||
extends X()
|
||||
end-extends {
|
||||
:method { ." Method 2 in Y" cr } ; defines method2
|
||||
}
|
||||
;
|
||||
|
||||
: Main
|
||||
static Y() y
|
||||
y => method1
|
||||
y => method2
|
||||
;
|
||||
|
||||
Main
|
||||
5
Task/Abstract-type/Go/abstract-type.go
Normal file
5
Task/Abstract-type/Go/abstract-type.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
interface {
|
||||
Method1(value float64) int
|
||||
SetName(name string)
|
||||
GetName() string
|
||||
}
|
||||
3
Task/Abstract-type/Haskell/abstract-type-1.hs
Normal file
3
Task/Abstract-type/Haskell/abstract-type-1.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Eq a where
|
||||
(==) :: a -> a -> Bool
|
||||
(/=) :: a -> a -> Bool
|
||||
5
Task/Abstract-type/Haskell/abstract-type-2.hs
Normal file
5
Task/Abstract-type/Haskell/abstract-type-2.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class Eq a where
|
||||
(==) :: a -> a -> Bool
|
||||
(/=) :: a -> a -> Bool
|
||||
x /= y = not (x == y)
|
||||
x == y = not (x /= y)
|
||||
2
Task/Abstract-type/Haskell/abstract-type-3.hs
Normal file
2
Task/Abstract-type/Haskell/abstract-type-3.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
func :: (Eq a) => a -> Bool
|
||||
func x = x == x
|
||||
1
Task/Abstract-type/Haskell/abstract-type-4.hs
Normal file
1
Task/Abstract-type/Haskell/abstract-type-4.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
data Foo = Foo {x :: Integer, str :: String}
|
||||
3
Task/Abstract-type/Haskell/abstract-type-5.hs
Normal file
3
Task/Abstract-type/Haskell/abstract-type-5.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
instance Eq Foo where
|
||||
(Foo x1 str1) == (Foo x2 str2) =
|
||||
(x1 == x2) && (str1 == str2)
|
||||
3
Task/Abstract-type/Haskell/abstract-type-6.hs
Normal file
3
Task/Abstract-type/Haskell/abstract-type-6.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class abstraction()
|
||||
abstract method compare(l,r) # generates runerr(700, "method compare()")
|
||||
end
|
||||
7
Task/Abstract-type/Java/abstract-type-1.java
Normal file
7
Task/Abstract-type/Java/abstract-type-1.java
Normal file
|
|
@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
5
Task/Abstract-type/Java/abstract-type-2.java
Normal file
5
Task/Abstract-type/Java/abstract-type-2.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
public interface Inter {
|
||||
int method1(double value);
|
||||
int method2(String name);
|
||||
int add(int a, int b);
|
||||
}
|
||||
34
Task/Abstract-type/Lua/abstract-type-1.lua
Normal file
34
Task/Abstract-type/Lua/abstract-type-1.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
BaseClass = {}
|
||||
|
||||
function class ( baseClass )
|
||||
local new_class = {}
|
||||
local class_mt = { __index = new_class }
|
||||
|
||||
function new_class:new()
|
||||
local newinst = {}
|
||||
setmetatable( newinst, class_mt )
|
||||
return newinst
|
||||
end
|
||||
|
||||
if not baseClass then baseClass = BaseClass end
|
||||
setmetatable( new_class, { __index = baseClass } )
|
||||
|
||||
return new_class
|
||||
end
|
||||
|
||||
function abstractClass ( self )
|
||||
local new_class = {}
|
||||
local class_mt = { __index = new_class }
|
||||
|
||||
function new_class:new()
|
||||
error("Abstract classes cannot be instantiated")
|
||||
end
|
||||
|
||||
if not baseClass then baseClass = BaseClass end
|
||||
setmetatable( new_class, { __index = baseClass } )
|
||||
|
||||
return new_class
|
||||
end
|
||||
|
||||
BaseClass.class = class
|
||||
BaseClass.abstractClass = abstractClass
|
||||
8
Task/Abstract-type/Lua/abstract-type-2.lua
Normal file
8
Task/Abstract-type/Lua/abstract-type-2.lua
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
A = class() -- New class A inherits BaseClass by default
|
||||
AA = A:class() -- New class AA inherits from existing class A
|
||||
B = abstractClass() -- New abstract class B
|
||||
BB = B:class() -- BB is not abstract
|
||||
A:new() -- Okay: New class instance
|
||||
AA:new() -- Okay: New class instance
|
||||
B:new() -- Error: B is abstract
|
||||
BB:new() -- Okay: BB is not abstract
|
||||
7
Task/Abstract-type/PHP/abstract-type-1.php
Normal file
7
Task/Abstract-type/PHP/abstract-type-1.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
abstract class Abs {
|
||||
abstract public function method1($value);
|
||||
abstract protected function method2($name);
|
||||
function add($a, $b){
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
5
Task/Abstract-type/PHP/abstract-type-2.php
Normal file
5
Task/Abstract-type/PHP/abstract-type-2.php
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
interface Inter {
|
||||
public function method1($value);
|
||||
public function method2($name);
|
||||
public function add($a, $b);
|
||||
}
|
||||
14
Task/Abstract-type/Perl/abstract-type-1.pl
Normal file
14
Task/Abstract-type/Perl/abstract-type-1.pl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package AbstractFoo;
|
||||
|
||||
use strict;
|
||||
|
||||
sub frob { die "abstract" }
|
||||
sub baz { die "abstract" }
|
||||
|
||||
sub frob_the_baz {
|
||||
my $self = shift;
|
||||
$self->frob($self->baz());
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
13
Task/Abstract-type/Perl/abstract-type-2.pl
Normal file
13
Task/Abstract-type/Perl/abstract-type-2.pl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package AbstractFoo;
|
||||
|
||||
use strict;
|
||||
|
||||
sub frob { ... }
|
||||
sub baz { ... }
|
||||
|
||||
sub frob_the_baz {
|
||||
my $self = shift;
|
||||
$self->frob($self->baz());
|
||||
}
|
||||
|
||||
1;
|
||||
12
Task/Abstract-type/Perl/abstract-type-3.pl
Normal file
12
Task/Abstract-type/Perl/abstract-type-3.pl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package AbstractFoo;
|
||||
|
||||
use Moose::Role;
|
||||
|
||||
requires qw/frob baz/;
|
||||
|
||||
sub frob_the_baz {
|
||||
my $self = shift;
|
||||
$self->frob($self->baz());
|
||||
}
|
||||
|
||||
1;
|
||||
12
Task/Abstract-type/Perl/abstract-type-4.pl
Normal file
12
Task/Abstract-type/Perl/abstract-type-4.pl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package AbstractFoo;
|
||||
|
||||
use Role::Tiny;
|
||||
|
||||
requires qw/frob baz/;
|
||||
|
||||
sub frob_the_baz {
|
||||
my $self = shift;
|
||||
$self->frob($self->baz());
|
||||
}
|
||||
|
||||
1;
|
||||
11
Task/Abstract-type/PicoLisp/abstract-type.l
Normal file
11
Task/Abstract-type/PicoLisp/abstract-type.l
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# In PicoLisp there is no formal difference between abstract and concrete classes.
|
||||
# There is just a naming convention where abstract classes start with a
|
||||
# lower-case character after the '+' (the naming convention for classes).
|
||||
# This tells the programmer that this class has not enough methods
|
||||
# defined to survive on its own.
|
||||
|
||||
(class +abstractClass)
|
||||
|
||||
(dm someMethod> ()
|
||||
(foo)
|
||||
(bar) )
|
||||
13
Task/Abstract-type/Python/abstract-type-1.py
Normal file
13
Task/Abstract-type/Python/abstract-type-1.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class BaseQueue(object):
|
||||
"""Abstract/Virtual Class
|
||||
"""
|
||||
def __init__(self):
|
||||
self.contents = list()
|
||||
raise NotImplementedError
|
||||
def Enqueue(self, item):
|
||||
raise NotImplementedError
|
||||
def Dequeue(self):
|
||||
raise NotImplementedError
|
||||
def Print_Contents(self):
|
||||
for i in self.contents:
|
||||
print i,
|
||||
21
Task/Abstract-type/Python/abstract-type-2.py
Normal file
21
Task/Abstract-type/Python/abstract-type-2.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
class BaseQueue():
|
||||
"""Abstract Class
|
||||
"""
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self):
|
||||
self.contents = list()
|
||||
|
||||
@abstractmethod
|
||||
def Enqueue(self, item):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def Dequeue(self):
|
||||
pass
|
||||
|
||||
def Print_Contents(self):
|
||||
for i in self.contents:
|
||||
print i,
|
||||
13
Task/Abstract-type/Racket/abstract-type.rkt
Normal file
13
Task/Abstract-type/Racket/abstract-type.rkt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#lang racket
|
||||
|
||||
(define animal-interface (interface () say))
|
||||
|
||||
(define cat% (class* object% (animal-interface) (super-new))) ;; error
|
||||
|
||||
(define cat% (class* object% (animal-interface)
|
||||
(super-new)
|
||||
(define/public (say)
|
||||
(display "meeeeew!"))))
|
||||
|
||||
(define tom (new cat%))
|
||||
(send tom say)
|
||||
17
Task/Abstract-type/Ruby/abstract-type.rb
Normal file
17
Task/Abstract-type/Ruby/abstract-type.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
require 'abstraction'
|
||||
|
||||
class AbstractQueue
|
||||
abstract
|
||||
def enqueue(object)
|
||||
raise NotImplementedError
|
||||
end
|
||||
def dequeue
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
||||
class ConcreteQueue < AbstractQueue
|
||||
def enqueue(object)
|
||||
puts "enqueue #{object.inspect}"
|
||||
end
|
||||
end
|
||||
10
Task/Abstract-type/Scala/abstract-type.scala
Normal file
10
Task/Abstract-type/Scala/abstract-type.scala
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
abstract class X {
|
||||
type A
|
||||
var B: A
|
||||
val C: A
|
||||
def D(a: A): A
|
||||
}
|
||||
|
||||
trait Y {
|
||||
val x: X
|
||||
}
|
||||
9
Task/Abstract-type/Tcl/abstract-type.tcl
Normal file
9
Task/Abstract-type/Tcl/abstract-type.tcl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
oo::class create AbstractQueue {
|
||||
method enqueue item {
|
||||
error "not implemented"
|
||||
}
|
||||
method dequeue {} {
|
||||
error "not implemented"
|
||||
}
|
||||
self unexport create new
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue