In a little project I am making to try and implement classes using lists, I am running into an annoying problem which is that when I change the child object, it modifies the parent as well - i.e. the child is somehow linked to the parent. I had a look in the Snap! manual and couldn't find any solution (at least, not one that I could understand well enough).
Essentially, what I want to find is the opposite of the 'inherit' block, something that stops my variable from inheriting. Another (slightly more accurate) comparison would be having the equivalent of the new keyword in JS. I expect I'm missing something really obvious here but any help would be appreciated.
Deep copying data structures is kinda neat, but also kinda not what OOP is really about. One of the big ideas behind OOP is that structures can be in relation to others, and that those relationships are dynamic, i.e. they make something change when something changes elsewhere. In "classical" (i.e. class based) OOP the relationship between classes and subclasses and between classes and instances is structural, i.e. adding or removing a slot in a super-structure gets automatically inherited by its dependents. In prototypal OOP the dynamic relationship also includes the values of individual slots.
Therefore OOP can actually be thought of not so much as duplication (deep copy) but as shallow copying in combination with copy-on-write. That "copy-on-write" part is the hard part
You completely lost me. I thought I understood this stuff! How I understand class/instance vs. protoype is that in class/instance the instances don't have methods, whereas in prototyping every object can have methods, and can be the "class" of other objects.
What I thought you were going to say is that inheritance doesn't involve copying at all, but sharing of pointers. I don't get the copy-on-write thing.
Classes: Subclasses share the same structure (slots, instance variables, methods) as their superclasses, same as instances share the structure (the slots, instance variables) of their class. Changing the structure of a (super-) class also changes the structure of all dependents (subclasses, instances), that's why it's not a deep copy.
Prototypes: Clones share mostly everything with their parent (shallow copy), but when they change the value of a slot it gets copied locally. Hence copy-on-write.
well, changing a "shared pointer" to a "new private one" is sort of a complicated technical definition for copy-on-write, isn't it? Especially since now a new slot that holds the pointer must be created.
The point isn't that whatever the value is get "copied", but the slot.