Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the proper term for Parent?

Tags:

objective-c

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.

like image 971
gargantuan Avatar asked Apr 02 '09 19:04

gargantuan


People also ask

What is the legal term for parent?

"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.

What is the formal definition of parent?

1 : a father or mother of a child. 2 : an animal or plant that produces offspring. parent. noun.


1 Answers

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.

like image 112
Jarret Hardie Avatar answered Oct 17 '22 09:10

Jarret Hardie