Objects in objective c. How to define?

Objects are instances of the class to use the class code, we need to create the object.
@interface Person : NSObject {
 NSString *_name; 
 NSInteger _age;
}

Here, in the newly created Person class declares two variables _name & _age. The sign of the stars is only about the object. Why the object is exactly _name? But if I create a class to find the area of a triangle by means of one formula ? There are only 4 variables, area of a triangle, side a, side B, and height. Here will be the object and marked with an asterisk? If the area of the triangle then it will be declared?

double *_areaTriangle; // ?
July 9th 19 at 13:46
2 answers
July 9th 19 at 13:48
Solution
"The sign of the stars" is placed where you do not declare the variable, and a pointer to it. Accordingly what you want - and then declare the pointers if you need.
Specifically, in the example with the triangle, I would not make any pointers. And square is not a variable, and method. Class - a triangle, with parameters - side and way - "calculate the area" "calculate perimeter" etc.
The area value it is necessary to assign a variable and display. - justine_Croo commented on July 9th 19 at 13:51
What is strange you have a class in this case. What is its functional part? - nicklaus commented on July 9th 19 at 13:54
: The class that will perform only 2 of the method, the calculation of area and output the result to the console. - justine_Croo commented on July 9th 19 at 13:57
Well, as an option - two methods. The first calculates the area and stores in the internal variable. The second prints to the console the variable. But IMHO it is not nice to do that. It is better to have one method which returns the area. And already there, where you call this method and memorize it in a variable and output the result to the console. - nicklaus commented on July 9th 19 at 14:00
July 9th 19 at 13:50
Here the focus still is that NSInteger is a scalar and the NSString class. ObjC classes can only be stored in the heap, but the scalars and C-structures can be stored in the heap and on the stack.

Find more questions by tags C++OOPObjective-C