I have a object called node, but want different implementations of those nodes while keeping an abstract model without the code processing them having to understand the implementation details.
Pseudo, about how I would do it in C++:
class node {
virtual void update();
virtual void init();
}
class houseNode : node {
void update();
void init();
}
I know about concepts in Nim which can be used to define and set certain traits on one or multiple types (setoid, monoid etc.). I also know about using composition over inheritance, using a procedural approach which I usually prefer as well. Sadly both do not really fit what I need for the above.
What is the best way to do the above in Nim?
type Node = ref object of RootObj
type HouseNode = ref object of Node
method update(node: Node) {.base.} = discard
method init(node: Node) {.base.} = discard
method update(house: HouseNode) =
# ...
method init(house: HouseNode) =
# ...
EDIT: uhh, is it a problem with the forum or is syntax highlighting and newlines supposed to disappear in codeblocks when there's no other text?
It's an parser bug in the RST parser. Have to put something before or after the code :)