Re: NSObject Exercise comments?
Re: NSObject Exercise comments?
- Subject: Re: NSObject Exercise comments?
- From: Andreas Mayer <email@hidden>
- Date: Sat, 10 Dec 2005 19:39:44 +0100
Am 10.12.2005 um 17:34 Uhr schrieb Lee Cullens:
I don't understand why one would use an indeterminate object
reference type unless there was intended polymorphism afoot, or in
the processing code a variable was being used for different objects
(which doesn't help readability) .
Ondra answered this already.
I suggest to follow the conventions; if only to not confuse the
reader. :)
I don't understand this point. Are you saying to use a generic
method name for a specific manipulation of specific instance
variables, or is the method name "description" a common convention
for a method that "presents" a display version of instance variables?
The latter. Every object responds to 'description'. It's common to
overwrite it in new classes to get a more helpful text representation
of those objects.
Also, it is often a good idea to use more generic method names so
that objects of different classes use similar method names for
similar functionality. Take container classes as an example: Each
container class responds to 'count', no matter if it is an array, a
dictionary or a set. This not only makes it easier to remember, but
it also allows a more abstract use. If I just want to know how many
object are in a collection, I need not care if it's an array or a
dictionary. That leads to more robust code (I can swap the collection
class without changing that code).
> > -(Fraction *) reduceFraction
However, it is a good point because it leads to unnecessary confusion.
That's actually the main point, I think. When I see a method that
returns an object, that object is usually a new one.
I know that there was a convention were the original object was
returned when ever possible, so that one could 'chain' method calls
together. But I think this is discouraged now. At least it's uncommon
and therefore confusing.
Also, I'm not sure it's a good idea to alter the object in that
method. Someone may still hold a reference to it and may not expect
it to suddenly change it's value. But *if* you do, make sure to
document it clearly.
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden