No description
Find a file
2021-06-09 10:05:39 +02:00
.github/workflows switch to github action 2021-06-09 10:02:30 +02:00
benchmarks prepare for merge: renamings / moved tests 2019-04-13 15:29:16 +02:00
dev first draft of typed based syntax 2019-04-16 23:35:46 +02:00
src/oop_utils fix init for generics 2019-05-01 16:20:32 +02:00
tests more tests 2019-05-01 10:20:55 +02:00
.gitignore initial commit from experiments 2019-03-24 17:39:22 +01:00
.watchcode.yaml added first unit tests for self block parsing 2019-05-01 09:31:40 +02:00
nim.cfg hide debug output behind defined(debugOOP) 2019-04-29 07:42:18 +02:00
oop_utils.nimble renamed tests 2019-04-20 18:39:28 +02:00
readme.md switch to github action 2021-06-09 10:02:30 +02:00
readme_closure_class.md adapted readme 2019-04-13 17:03:19 +02:00
readme_standard_class.md adapted readme 2019-04-13 17:03:19 +02:00

oop_utils Build Status license

oop_utils provides macros that allow to easily create OOP class hierarchies.

It comes in two different flavors:

  • Standard classes: Allows to define type hierarchies based on Nim's standard method dispatch.
  • Closure classes: Allows to define type hierarchies based on closure method dispatch.

The two approaches have minor syntactical differences, but share the same general scheme. For comparison:

import oop_utils/standard_class

# A standard class:
# - The object instance is attached to a `self` symbol.
# - Initialization + field definitions go into the ctor proc.
class(Counter):
  ctor(newCounter) proc(init: int) =
    self:
      counter = init

  method inc*() {.base.} = self.counter.inc
  method dec*() {.base.} = self.counter.dec
  method get*(): int {.base.} = self.counter

vs.

import oop_utils/closure_class

# A closure class:
# - No `self` symbol required.
# - Initialization + field definitions go into main scopre to emphasize closure nature.
class(Counter):
  ctor(newCounter) proc(init: int)

  var counter = init

  proc inc*() = counter.inc
  proc dec*() = counter.dec
  proc get*(): int = counter