Skip to content

Ideas for Object Orientation

Alexander Schneider edited this page Jan 24, 2015 · 7 revisions

##Don't do it at all Probably the easiest solution - use maps to act like objects and leave it at that. Have a couple of defined methods an object must implement to be iterable, etc.

##How CoffeeScript does it: http://rzrsharp.net/2011/06/21/classes-in-coffeescript.html

##Traits (methods or properties that an object must implement to be considered valid): Suggestions/edits welcome Syntax example:

iterable := trait:
  next()
  has_next(): bool
end

ordered_iterable := trait:
  infuse iterable
  index(): int
end

Usage suggestions:

[1, 2, 3] is iterable # returns true
[1, 2, 3] is ordered_iterable # returns true
<1, 2, 3> is ordered_iterable # returns false

We probably want to come up with some immutable map syntax that can be used to represent an object.

This should have ability to access variables and functions inside an object like properties rather than using the traditional ["<identifier>"] selector. Something like:

# Behaves like a class
Circle := type:
    init := () ->
        # constructor code goes here
    get_area := () ->
        # function code goes here
end

# instantiation implicity calls 'init'
circle := new Circle()

Which can be accessed by

# x.<property>
x.foo(bar)
x.bar

but either immutable or some very limited mutability (I.E. can only change properties, not assign them)

Anything you like/don't like/would change?

Clone this wiki locally