In Actionscipt, Parent means the object which contains the instance. So if a car has a wheel, wheel can tell the car to move forward with
parent.moveForward
However, in Obj-C, parent refers to the super class (not sure why they have super and parent mean the same thing).
I can't find any equivalent to the Action-script style parent, but then I don't really know what to even look for. Is there an easy way to do this in Obj-C, or do I have to manually pass a reference to the instance when I create it? I've tried this and It's throwing an error, but since I'm new to Obj-C, I just wanted to make sure I'm taking the right course of action.
"Parent" means a woman who gives birth to a child and a man whose consent to the adoption of the child would be required. If a child has been legally adopted, the term "parent" means the adoptive mother or father of the child.
1 : a father or mother of a child. 2 : an animal or plant that produces offspring. parent. noun.
Interesting... I did not know that Actionscript used the word "parent" in that way.
There are two separate concepts at work here: inheritance and composition. The term parent
is used in both cases in Objective-C and many other object-oriented languages.
In Objective-C, a class which inherits from another refers to that "other" class as its ancestor. While many people use the term superclass
, in fact you could quite legitimately use the word parent
. As the names imply, this is object "inheritance".
Object "composition", on the other hand, is what you've described with the example of the car and wheel. A car is composed of several other objects, one or more of which is the wheel. I must admit, I've not often heard the term parent
used in this context to refer to the car. Usually, you'll probably find most people in the Objective-C world would recognize the car
by the label "container". In the case of a tree-style data structure like an XML document, though, we often talk about parent nodes and child nodes. The parent contains the children, so using the word "parent" in a composition relationship is also apposite depending on the type of relationship. I don't think you'll find many Objective-C programmers using the "parent" word in composition scenarios outside of a tree structure, though.
The distinction is often likened to a "has a" versus "is a" relationship: identity versus possession. In inheritance, the child "is a" subtype of its parent. In composition, on the other hand, the car "has a" wheel, or a parent node in a tree "has a" collection of child nodes.
Edit: Kendall Helmstetter-Gelner below added some good comments on the part of your question related to instances and passing references. If you have a particular block of code and a specific error message, please feel free to update your question with them and we'll try to help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With