Monday, 19 August 2013

Accessing obj as property vs method param (style preferences)

Accessing obj as property vs method param (style preferences)

When it comes to accessing objects from different methods in the same
class, from what I understand, these are two ways to do it. Given that I
DO want to hold a property pointer to this object, which is the better way
to go about this? I've been thinking about this for a while, and wondered
if there is a preference consensus.
#1:
NSArray *array = ... // Get array from somewhere
self.myArray = array;
[self doSomethingToMyArray];
This method takes no parameter and accesses the array via its own property
via self
- (void)doSomethingToMyArray
{
// Do stuff to the array via self.myArray
[self.myArray ...];
}
Vs #2:
NSArray *array = ... // Get array from somewhere
self.myArray = array;
[self doSomething:array];
This method takes an array and accesses the array via its own method
parameter
- (void)doSomething:(NSArray *)array
{
// Do stuff to the array via method parameter "array"
[array ...];
}

No comments:

Post a Comment