Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -9,3 +9,5 @@ It is important not to confuse this ''abstractness'' (of implementation) with on
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.
{{omit from|MiniZinc|no ability to declare new types at all}}

View file

@ -0,0 +1,29 @@
package main
import "fmt"
type Beast interface {
Cry() string
}
type Pet struct{}
type Cat struct {
Pet
}
func (p Pet) Name(b Beast) {
fmt.Println(b.Cry())
}
func (p Pet) Cry() string {
return "Woof"
}
func (c Cat) Cry() string {
return "Meow"
}
func main() {
p := Pet{}
c := Cat{}
p.Name(p) // prt Woof
c.Name(c) // prt Meow
}

View file

@ -0,0 +1,29 @@
public abstract class Animal : Object {
public void eat() {
print("Chomp! Chomp!\n");
}
public abstract void talk();
}
public class Mouse : Animal {
public override void talk() {
print("Squeak! Squeak!\n");
}
}
public class Dog : Animal {
public override void talk() {
print("Woof! Woof!\n");
}
}
void main() {
Dog mike = new Dog();
Mouse scott = new Mouse();
mike.talk();
mike.eat();
scott.talk();
scott.eat();
}