How To Check Inheritance And Implementation
Print Hello World
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Use Lists
Use Arrays
Make A Class Hierarchy
Use Nil And Nilable Types
Use Dynamic Typing
Declare Variable Number Of Args
Read And Write Files
Check Inheritance And Implementation
Customize Object Equality
Pass References To Methods
Translate Pseudo Code To Cobra 1
Translate Pseudo Code To Cobra 2
Implement IEnumerable 1
Implement IEnumerable 2
Iterate Through Recursive Data With Yield
Make A Collection Class
Declare Contracts
Threads
Win Forms
WPF
GTK
Qyoto
Access MySQL
XNA
Open TK
 
"""
CheckInheritanceAndImplementation.cobra

To check if a value inherits a particular class, use the `inherits` operator
which gives a boolean value (true or false):

    isACar = vehicle inherits Car

To check if a value implements a particular interface, use the `implements`
operator:

    isComparable = x implements IComparable

If you use these in an `if` statement with a variable, you can treat the
variable as the given class or interface with no explicit typecasting:

    if vehicle inherits Car
        vehicle.drive
        carCrusher.crush(vehicle)
    else if vehicle inherits Plane
        vehicle.fly
        airplaneGraveyard.take(vehicle)

Of course, it would be nice if Car and Plane were derived from a common Vehicle
class with an `operate` method, but sometimes you don't have control over the
class hierarchy you are working with.
"""


class BankAccount

    def deposit(x as Object)
        if x inherits Money
            _balance += x.amount
        else if x inherits decimal
            _balance += x
        else if x inherits int
            _balance += x
        else
            throw FallThroughException(x)

    # ^ In a way this is a bad example. Since we have control over the code,
    # providing method overloads of `deposit` would make the BankAccount interface
    # more clear and the program run faster.

    def deposit2(x)  # dynamic typed arg
        if x inherits Money
            _balance += x.amount
        else
            _balance = _balance + x  # woops, += isn't implemented for dynamic yet

    get balance from var as decimal


class Money

    cue init(amount as decimal)
        base.init
        _amount = amount

    get amount from var as decimal


class Program

    def main
        ba = BankAccount()
        ba.deposit(10)
        ba.deposit(Money(10))
        assert ba.balance == 20