Typedef struct vs. Object - Benefits

I plan to define a class that, among its properties, contains the coordinates for the x / y grid. However, I'm not sure about the “best” way to approach this design. This is a very simple problem, I just want to do it right and make excuses!

One solution should be two properties of type " int", one for x and one for y, inside the object.

The other will define a typedef structure of two ints containing x / y values ​​and calling it <ClassPrefix>Coordinate. The like CGSize?

Are there other / better ways to do this? Which is preferable? Not sure how to make excuses anyway.

Thank!

Tim.

+5
source share
3 answers

" ?" :

  • ?. "", struct ; " ", .
  • ?. "" , ; struct .
  • ?. "" , struct .
  • ?. "" , struct .

, , ; , "".

+11

@dasblinkenlight, :

  • ?
    .

  • (= ) ( C, NSArray)? (= )?
    .

  • (int, float, struct ..) /?
    a struct .

+4

.

, . , .

A structure is faster, but a complex degree and the most uncomfortable thing is that a structure cannot contain objects or a method.

In your example, if you just use it for coordinates, I suggest you use struct. But it depends on your design and code. Best of all, there is no absolute judgment.

+1
source

All Articles