ID:2301354
 
I'm a C++ programmer, and I'm curious, is it possible to create an abstract object with DM. I'd like to make a parent object that when created, somewhere else in the code it can become one of it's children, without having to define exactly what child it is.

For instance;

obj/A
var foo

obj/A/B
foo = bar

obj/A/C
foo = rab

something/s
obj/A/x = new Obj/A/C()

I'd like to be able to define Obj/A/x but if the code needs x to become Obj/A/C it can become said object. Apologies if I'm being incredibly vague, I'm not the best at describing the question.
DM doesn't allow abstract classes. It's single-inheritance only, and when the original programmer left the language, he was planning to implement interfaces. It never happened.


That doesn't mean you have to totally give up on the idea, though.

DM allows runtime accesses rather than compile time accesses. You can use the ":" operator to invoke methods and access members of an object.

obj
proc
HerpyDerp()
mob
proc
HerpyDerp()

//in a proc
for(var/atom/movable/o in world)
o.HerpyDerp() //this will fail to compile.



The above will fail to compile because /atom/movable is the root type of /obj and /mob, and o is cast as a movable atom. movable atom doesn't have the proc HerpyDerp.

You can get around this by using the ":" operator.

//in a proc
for(var/atom/movable/o in world)
o:HerpyDerp()


The above will compile. That's because ":" doesn't have to know which method it's going to invoke until runtime. "." has to be able to resolve it at compile-time.

Using ":" you can basically just redefine behavior all over your code and pretend you are using abstract classes or interfaces.
Oh that's rather interesting. I think that's exactly what I needed to know, thanks.