Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,7 @@
---
category:
- Object oriented
- Type System
- Encyclopedia
from: http://rosettacode.org/wiki/Inheritance/Single
note: Basic language learning

View file

@ -0,0 +1,60 @@
::: ''This task is about derived types;   for implementation inheritance, see [[Polymorphism]].
Inheritance is an operation of [[type algebra]] that creates a new type from one or several parent types.
The obtained type is called '''derived type'''.
It inherits some of the properties of its parent types.
Usually inherited properties are:
:::*   methods
:::*   components
:::*   parts of the representation
The [[classes | class]] of the new type is a   '''subclass'''   of the classes rooted in the parent types.
When all (in certain sense) properties of the parents are preserved by the derived type,   it is said to be a [[wp:Liskov_substitution_principle|Liskov subtype]].
When properties are preserved then the derived type is ''substitutable'' for its parents in all contexts.   Usually full substitutability is achievable only in some contexts.
Inheritance is
:::*   '''single''', when only one parent is allowed
:::*   '''[[multiple inheritance | multiple]]''', otherwise
Some single inheritance languages usually allow multiple inheritance for certain [[abstract type]]s, interfaces in particular.
Inheritance can be considered as a relation parent-child.
Parent types are sometimes called '''supertype''', the derived ones are '''subtype'''.   This relation is [[wp:Transitive_relation|transitive]] and [[wp:Reflexive_relation|reflexive]].
Types bound by the relation form a [[wp:Directed_acyclic_graph directed acyclic graph]] (ignoring reflexivity).
With single inheritance it becomes a [[wp:Tree_(graph_theory)|tree]].
;Task:
Show a tree of types which inherit from each other.
:::   At the top of the tree should be a class called   '''Animal'''.
:::   The second level should have '''Dog''' and '''Cat'''.
:::   Under   '''Dog'''   should be   '''Lab'''   and   '''Collie'''.
::: &nbsp; None of the classes need to have any functions, &nbsp; the only thing they need to do is inherit from the specified superclasses <br> &nbsp; (overriding functions should be shown in [[Polymorphism]]).
The tree should look like this:
<pre>
Animal
/\
/ \
/ \
Dog Cat
/\
/ \
/ \
Lab Collie
</pre>
<br><br>

View file

@ -0,0 +1,15 @@
T Animal
{
}
T Dog(Animal)
{
}
T Cat(Animal)
{
}
T Lab(Dog)
{
}
T Collie(Dog)
{
}

View file

@ -0,0 +1,3 @@
public class Animal {
// ...
}

View file

@ -0,0 +1,3 @@
public class Cat extends Animal {
// ...
}

View file

@ -0,0 +1,3 @@
public class Dog extends Animal {
// ...
}

View file

@ -0,0 +1,3 @@
public class Lab extends Dog {
// ...
}

View file

@ -0,0 +1,3 @@
public class Collie extends Dog {
// ...
}

View file

@ -0,0 +1,13 @@
package Inheritance is
type Animal is tagged private;
type Dog is new Animal with private;
type Cat is new Animal with private;
type Lab is new Dog with private;
type Collie is new Dog with private;
private
type Animal is tagged null record;
type Dog is new Animal with null record;
type Cat is new Animal with null record;
type Lab is new Dog with null record;
type Collie is new Dog with null record;
end Inheritance;

View file

@ -0,0 +1,3 @@
class Animal{
//functions go here...
}

View file

@ -0,0 +1,3 @@
class Dog extends Animal {
//functions go here...
}

View file

@ -0,0 +1,3 @@
class Cat extends Animal {
//functions go here...
}

View file

@ -0,0 +1,3 @@
class Lab extends Dog {
//functions go here...
}

View file

@ -0,0 +1,3 @@
class Collie extends Dog {
//functions go here...
}

View file

@ -0,0 +1,14 @@
OBJECT animal
ENDOBJECT
OBJECT dog OF animal
ENDOBJECT
OBJECT cat OF animal
ENDOBJECT
OBJECT lab OF dog
ENDOBJECT
OBJECT collie OF dog
ENDOBJECT

View file

@ -0,0 +1,18 @@
script Animal
end script
script Dog
property parent : Animal
end script
script Cat
property parent : Animal
end script
script Lab
property parent : Dog
end script
script Collie
property parent : Dog
end script

View file

@ -0,0 +1,14 @@
dog := new Collie
MsgBox, % "A " dog.__Class " is a " dog.base.base.__Class " and is part of the " dog.kingdom " kingdom."
class Animal {
static kingdom := "Animalia" ; Class variable
}
class Dog extends Animal {
}
class Cat extends Animal {
}
class Lab extends Dog {
}
class Collie extends Dog {
}

View file

@ -0,0 +1,20 @@
INSTALL @lib$+"CLASSLIB"
DIM Animal{method}
PROC_class(Animal{})
DIM Cat{method}
PROC_inherit(Cat{}, Animal{})
PROC_class(Cat{})
DIM Dog{method}
PROC_inherit(Dog{}, Animal{})
PROC_class(Dog{})
DIM Labrador{method}
PROC_inherit(Labrador{}, Dog{})
PROC_class(Labrador{})
DIM Collie{method}
PROC_inherit(Collie{}, Dog{})
PROC_class(Collie{})

View file

@ -0,0 +1,24 @@
class Animal
{
// ...
};
class Dog: public Animal
{
// ...
};
class Lab: public Dog
{
// ...
};
class Collie: public Dog
{
// ...
};
class Cat: public Animal
{
// ...
};

View file

@ -0,0 +1,29 @@
class Animal
{
/* ... */
// ...
}
class Dog : Animal
{
/* ... */
// ...
}
class Lab : Dog
{
/* ... */
// ...
}
class Collie : Dog
{
/* ... */
// ...
}
class Cat : Animal
{
/* ... */
// ...
}

View file

@ -0,0 +1,39 @@
CLASS-ID. Animal.
*> ...
END CLASS Animal.
CLASS-ID. Dog INHERITS Animal.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Animal.
*> ...
END CLASS Dog.
CLASS-ID. Cat INHERITS Animal.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Animal.
*> ...
END CLASS Cat.
CLASS-ID. Lab INHERITS Dog.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Dog.
*> ...
END CLASS Lab.
CLASS-ID. Collie INHERITS Dog.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Dog.
*> ...
END CLASS Collie.

View file

@ -0,0 +1,3 @@
public class Drums{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class LatinKit extends Drums{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class ElectronicKit extends Drums{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class Congas extends LatinKit{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class TechnoDrums extends ElectronicKit{
//functions go here...
}

View file

@ -0,0 +1,5 @@
(gen-class :name Animal)
(gen-class :name Dog :extends Animal)
(gen-class :name Cat :extends Animal)
(gen-class :name Lab :extends Dog)
(gen-class :name Collie :extends Dog)

View file

@ -0,0 +1,4 @@
(derive ::dog ::animal)
(derive ::cat ::animal)
(derive ::lab ::dog)
(derive ::collie ::dog)

View file

@ -0,0 +1,6 @@
user> (isa? ::dog ::animal)
true
user> (isa? ::dog ::cat)
false
user> (isa? ::collie ::animal)
true

View file

@ -0,0 +1,5 @@
class Animal
class Cat extends Animal
class Dog extends Animal
class Lab extends Dog
class Collie extends Dog

View file

@ -0,0 +1,28 @@
class Animal
(@name) ->
move: (meters) ->
alert @name + " moved #{meters}m."
class Snake extends Animal
-> super ...
move: ->
alert 'Slithering...'
super 5
class Horse extends Animal
-> super ...
move: ->
alert 'Galloping...'
super 45
sam = new Snake 'Sammy the Python'
tom = new Horse 'Tommy the Palomino'
sam.move!
tom.move!

View file

@ -0,0 +1,33 @@
STRUC Animal
DIM Species$ OF 20
ENDSTRUC Animal
STRUC Dog
INHERIT Animal
DIM Race$ OF 20
FUNC New CONSTRUCTOR
Species$="Dog"
ENDFUNC New
ENDSTRUC Dog
STRUC Cat
INHERIT Animal
DIM Race$ OF 20
FUNC New CONSTRUCTOR
Species$="Cat"
ENDFUNC New
ENDSTRUC Cat
STRUC Lab
INHERIT Dog
FUNC New CONSTRUCTOR
Race$:="Lab"
ENDFUNC New
ENDSTRUC Lab
STRUC Collie
INHERIT Dog
FUNC New CONSTRUCTOR
Race$:="Collie"
ENDFUNC New
ENDSTRUC Collie

View file

@ -0,0 +1,5 @@
(defclass animal () ())
(defclass dog (animal) ())
(defclass lab (dog) ())
(defclass collie (dog) ())
(defclass cat (animal) ())

View file

@ -0,0 +1,5 @@
(defstruct animal)
(defstruct (dog (:include animal)))
(defstruct (lab (:include dog)))
(defstruct (collie (:include dog)))
(defstruct (cat (:include animal)))

View file

@ -0,0 +1,9 @@
;;; ASN.1 serialization logic specialized for animal class
(defmethod serialize-to-asn-1 ((a animal))
#| ... |#
)
;;; casually introduce the method over strings too; no relation to animal
(defmethod serialize-to-asn-1 ((s string))
#| ... #|
)

View file

@ -0,0 +1,6 @@
TYPE
Animal = ABSTRACT RECORD (* *) END;
Cat = RECORD (Animal) (* *) END; (* final record (cannot be extended) - by default *)
Dog = EXTENSIBLE RECORD (Animal) (* *) END; (* extensible record *)
Lab = RECORD (Dog) (* *) END;
Collie = RECORD (Dog) (* *) END;

View file

@ -0,0 +1,21 @@
class Animal {
// ...
}
class Dog: Animal {
// ...
}
class Lab: Dog {
// ...
}
class Collie: Dog {
// ...
}
class Cat: Animal {
// ...
}
void main() {}

View file

@ -0,0 +1,12 @@
type
Animal = class(TObject)
private
// private functions/variables
public
// public functions/variables
end;
type Dog = class(Animal) end;
type Cat = class(Animal) end;
type Collie = class(Dog) end;
type Lab = class(Dog) end;

View file

@ -0,0 +1,12 @@
type
Animal = class(TObject)
private
// private functions/variables
public
// public functions/variables
end;
Dog = class(Animal);
Cat = class(Animal);
Collie = class(Dog);
Lab = class(Dog);

View file

@ -0,0 +1,18 @@
def makeType(label, superstamps) {
def stamp {
to audit(audition) {
for s in superstamps { audition.ask(s) }
return true
}
}
def guard {
to coerce(specimen, ejector) {
if (__auditedBy(stamp, specimen)) {
return specimen
} else {
throw.eject(ejector, `$specimen is not a $label`)
}
}
}
return [guard, stamp]
}

View file

@ -0,0 +1,7 @@
def [Animal, AnimalStamp] := makeType("Animal", [])
def [Cat, CatStamp] := makeType("Cat", [AnimalStamp])
def [Dog, DogStamp] := makeType("Dog", [AnimalStamp])
def [Lab, LabStamp] := makeType("Lab", [DogStamp])
def [Collie, CollieStamp] := makeType("Collie", [DogStamp])

View file

@ -0,0 +1,3 @@
def fido implements LabStamp {}
def tom implements CatStamp {}
def brick {} # not an animal

View file

@ -0,0 +1,17 @@
? fido :Animal
# value: <fido>
? fido :Cat
# problem: <fido> is not a Cat
? fido :Lab
# value: <fido>
? tom :Animal
# value: <tom>
? tom :Cat
# value: <tom>
? brick :Animal
# problem: <brick> is not a Animal

View file

@ -0,0 +1,3 @@
class
ANIMAL
end

View file

@ -0,0 +1,5 @@
class
DOG
inherit
ANIMAL
end

View file

@ -0,0 +1,5 @@
class
CAT
inherit
ANIMAL
end

View file

@ -0,0 +1,5 @@
class
LAB
inherit
DOG
end

View file

@ -0,0 +1,5 @@
class
COLLIE
inherit
DOG
end

View file

@ -0,0 +1,24 @@
class Animal
{
// ...
}
class Dog : Animal
{
// ...
}
class Lab : Dog
{
// ...
}
class Collie : Dog
{
// ...
}
class Cat : Animal
{
// ...
}

View file

@ -0,0 +1,15 @@
type Animal() =
class // explicit syntax needed for empty class
end
type Dog() =
inherit Animal()
type Lab() =
inherit Dog()
type Collie() =
inherit Dog()
type Cat() =
inherit Animal()

View file

@ -0,0 +1,5 @@
TUPLE: animal ;
TUPLE: dog < animal ;
TUPLE: cat < animal ;
TUPLE: lab < dog ;
TUPLE: collie < dog ;

View file

@ -0,0 +1,19 @@
class Animal {
# ...
}
class Dog : Animal {
# ...
}
class Cat : Animal {
# ...
}
class Lab : Dog {
# ...
}
class Collie : Dog {
# ...
}

View file

@ -0,0 +1,19 @@
class Animal
{
}
class Dog : Animal
{
}
class Cat : Animal
{
}
class Lab : Dog
{
}
class Collie : Dog
{
}

View file

@ -0,0 +1,7 @@
include 4pp/lib/foos.4pp
:: Animal class end-class {} ;
:: Dog extends Animal end-extends {} ;
:: Cat extends Animal end-extends {} ;
:: Lab extends Dog end-extends {} ;
:: Collie extends Dog end-extends {} ;

View file

@ -0,0 +1,7 @@
include FMS2LL.f
:class Animal ;class
:class Dog <super Animal ;class
:class Cat <super Animal ;class
:class Lab <super Dog ;class
:class Collie <super Dog ;class

View file

@ -0,0 +1,18 @@
module anim
type animal
end type animal
type, extends(animal) :: dog
end type dog
type, extends(animal) :: cat
end type cat
type, extends(dog) :: lab
end type lab
type, extends(dog) :: collie
end type collie
end module anim

View file

@ -0,0 +1,21 @@
' FB 1.05.0 Win64
Type Animal Extends Object ' to enable virtual methods etc. if needed
' ...
End Type
Type Dog Extends Animal
' ...
End Type
Type Cat Extends Animal
' ...
End Type
Type Lab Extends Dog
' ...
End Type
Type Collie Extends Dog
' ...
End Type

View file

@ -0,0 +1,32 @@
package main
type animal struct {
alive bool
}
type dog struct {
animal
obedienceTrained bool
}
type cat struct {
animal
litterBoxTrained bool
}
type lab struct {
dog
color string
}
type collie struct {
dog
catchesFrisbee bool
}
func main() {
var pet lab
pet.alive = true
pet.obedienceTrained = false
pet.color = "yellow"
}

View file

@ -0,0 +1,3 @@
class Animal{
//contents go here...
}

View file

@ -0,0 +1,3 @@
class Dog extends Animal{
//contents go here...
}

View file

@ -0,0 +1,3 @@
class Cat extends Animal{
//contents go here...
}

View file

@ -0,0 +1,3 @@
class Lab extends Dog{
//contents go here...
}

View file

@ -0,0 +1,3 @@
class Collie extends Dog{
//contents go here...
}

View file

@ -0,0 +1,5 @@
class Animal a
class Animal a => Cat a
class Animal a => Dog a
class Dog a => Lab a
class Dog a => Collie a

View file

@ -0,0 +1,3 @@
class Animal {
// ...
}

View file

@ -0,0 +1,3 @@
class Cat extends Animal {
// ...
}

View file

@ -0,0 +1,3 @@
class Dog extends Animal {
// ...
}

View file

@ -0,0 +1,3 @@
class Lab extends Dog {
// ...
}

View file

@ -0,0 +1,3 @@
class Collie extends Dog {
// ...
}

View file

@ -0,0 +1,14 @@
class Animal ()
end
class Dog : Animal ()
end
class Cat : Animal ()
end
class Lab : Dog ()
end
class Collie : Dog ()
end

View file

@ -0,0 +1,5 @@
An animal is a kind of thing.
A cat is a kind of animal.
A dog is a kind of animal.
A collie is a kind of dog.
A lab is a kind of dog.

View file

@ -0,0 +1,5 @@
Animal := Object clone
Cat := Animal clone
Dog := Animal clone
Collie := Dog clone
Lab := Dog clone

View file

@ -0,0 +1 @@
coclass 'Animal'

View file

@ -0,0 +1,2 @@
coclass 'Dog'
coinsert 'Animal'

View file

@ -0,0 +1,2 @@
coclass 'Cat'
coinsert 'Animal'

View file

@ -0,0 +1,2 @@
coclass 'Lab'
coinsert 'Dog'

View file

@ -0,0 +1,2 @@
coclass 'Collie'
coinsert 'Dog'

View file

@ -0,0 +1,4 @@
coinsert_Dog_ 'Animal'
coinsert_Cat_ 'Animal'
coinsert_Lab_ 'Dog'
coinsert_Collie_ 'Dog'

View file

@ -0,0 +1,3 @@
public class Animal{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class Dog extends Animal{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class Cat extends Animal{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class Lab extends Dog{
//functions go here...
}

View file

@ -0,0 +1,3 @@
public class Collie extends Dog{
//functions go here...
}

View file

@ -0,0 +1,3 @@
function Animal() {
// ...
}

View file

@ -0,0 +1,4 @@
function Dog() {
// ...
}
Dog.prototype = new Animal();

View file

@ -0,0 +1,4 @@
function Cat() {
// ...
}
Cat.prototype = new Animal();

View file

@ -0,0 +1,4 @@
function Collie() {
// ...
}
Collie.prototype = new Dog();

View file

@ -0,0 +1,4 @@
function Lab() {
// ...
}
Lab.prototype = new Dog();

View file

@ -0,0 +1,4 @@
Animal.prototype.speak = function() {print("an animal makes a sound")};
var lab = new Lab();
lab.speak(); // shows "an animal makes a sound"

View file

@ -0,0 +1,6 @@
abstract type Animal end
abstract type Dog <: Animal end
abstract type Cat <: Animal end
struct Lab <: Dog end
struct Collie <: Dog end

View file

@ -0,0 +1,15 @@
class Animal [
#Method goes here
];
class Dog from Animal [
#Method goes here
];
class Lab from Dog [
#Method goes here
];
class collie from Dog [
#Method goes here
];

View file

@ -0,0 +1,32 @@
// version 1.0.6
open class Animal {
override fun toString() = "animal"
}
open class Dog : Animal() {
override fun toString() = "dog"
}
class Cat : Animal() {
override fun toString() = "cat"
}
class Labrador : Dog() {
override fun toString() = "labrador"
}
class Collie : Dog() {
override fun toString() = "collie"
}
fun main(args: Array<String>) {
val felix: Animal = Cat()
val rover: Animal = Dog()
val bella: Dog = Labrador()
val casey: Dog = Collie()
println("Felix is a $felix")
println("Rover is a $rover")
println("Bella is a $bella")
println("Casey is a $casey")
}

View file

@ -0,0 +1,24 @@
define animal => type {
data public gender::string
}
define dog => type {
parent animal
}
define cat => type {
parent animal
}
define collie => type {
parent dog
}
define lab => type {
parent dog
}
local(myanimal = lab)
#myanimal -> gender = 'Male'
#myanimal -> gender

View file

@ -0,0 +1,19 @@
Animal ::= Object clone tap {
;; Methods go here...
}.
Dog ::= Animal clone tap {
;; Methods go here...
}.
Cat ::= Animal clone tap {
;; Methods go here...
}.
Lab ::= Dog clone tap {
;; Methods go here...
}.
Collie ::= Dog clone tap {
;; Methods go here...
}.

View file

@ -0,0 +1,2 @@
-- parent script "Animal"
-- ...

View file

@ -0,0 +1,7 @@
-- parent script "Dog"
property ancestor
on new (me)
me.ancestor = script("Animal").new()
return me
end

View file

@ -0,0 +1,7 @@
-- parent script "Cat"
property ancestor
on new (me)
me.ancestor = script("Animal").new()
return me
end

View file

@ -0,0 +1,7 @@
-- parent script "Lab"
property ancestor
on new (me)
me.ancestor = script("Dog").new()
return me
end

View file

@ -0,0 +1,7 @@
-- parent script "Collie"
property ancestor
on new (me)
me.ancestor = script("Dog").new()
return me
end

View file

@ -0,0 +1,3 @@
Section Header
+ name := ANIMAL;
// ...

Some files were not shown because too many files have changed in this diff Show more