Skip to content

Instantly share code, notes, and snippets.

@pbouzakis
Created March 31, 2020 14:32
Show Gist options
  • Save pbouzakis/c773db761baa93d9617066a4cc51c600 to your computer and use it in GitHub Desktop.
Save pbouzakis/c773db761baa93d9617066a4cc51c600 to your computer and use it in GitHub Desktop.
// OOPS VIOLATION OF LISKOV!! Bad bad
Rectangle {
width(val) = _width = val
height(val) = _height = val
area() = width() * height()
}
test_area(rect: Rectangle) {
rect.width(4)
rect.height(5)
assert(rect.area() == 20)
}
Square extends Rectangle {
width(val) = _width = val, _height = val
height(val) = width(val)
}
// TO FIX
interface Shape() {
area()
}
Rectangle implements Shape {
width(val) = _width = val
height(val) = _height = val
area() = width() * height()
}
abstract Foo {
baz() = val = 5
bar() = drink = lotsOf()
abstract cooool()
}
CoolFoo extends Foo {
cooool() = singASong()
}
f = Foo()
Square implements Shape {
size(val) = _size = val;
area() = _size ^ 2;
}
test_area(shape) {
assert(rect.area() == 20)
}
// MODULE
// either in file foo.pbo
module {
bar() = jjkfdkjfld
baz() = fjkldsfjdslk
}
class Bat {
bar() = jjkfdkjfld
baz() = fjkldsfjdslk
}
// file baz.pbo
import bar, baz from foo
import Bar from foo
bar()
baz()
b = Bar(2)
c = Bar(2343)
b.foo()
c.foo()
bar()
// file baz2.pbo
import foo
foo.bar()
foo.baz()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment