Amazon.com Widgets Program 8.3 Square.m page 164 (156 3rd edition)
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 20, 2013, 04:39:30 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Program Examples
| | |-+  Chapter 8
| | | |-+  Program 8.3 Square.m page 164 (156 3rd edition)
Pages: [1]   Go Down
Print
Author Topic: Program 8.3 Square.m page 164 (156 3rd edition)  (Read 1713 times)
wellaged37
Newbie
*
Posts: 39






« on: February 20, 2009, 07:41:11 AM »

code fragment:  [self setWidth: s andHeight: s];

Is it legal to use as an alternative to this fragment, the following?

width = s; height = s;
« Last Edit: August 04, 2011, 08:46:35 AM by fujilla » Logged
esc
Global Moderator
Full Member
*****
Posts: 230






« Reply #1 on: February 20, 2009, 11:23:43 AM »

Yes, you have direct access to the parent/super class' instance variables.
Logged
wellaged37
Newbie
*
Posts: 39






« Reply #2 on: February 20, 2009, 01:12:15 PM »

Thanks, I thought as much.
Logged
mdeh
Full Member
***
Posts: 166






« Reply #3 on: February 20, 2009, 02:00:19 PM »

Thanks, I thought as much.


But....what you **Don't** have access to is anything else important that [setWidth: andHeight:] might also be doing. For instance, lets say that you were actually copying instead of directly assigning the variable, with your method you would
a) either have to duplicate code
b) have 2 different sets of values stored

So, as a general principle, use what you already have.
« Last Edit: February 20, 2009, 02:02:09 PM by mdeh » Logged
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #4 on: February 20, 2009, 05:07:01 PM »

Yes, and also if you have synthesized accessor methods, in general you'll want to use the synthesized methods and not do direct assignment to the instance variables.

Cheers,

Steve
Logged
wellaged37
Newbie
*
Posts: 39






« Reply #5 on: February 21, 2009, 07:37:24 AM »

Thanks mdeh and steve for the additional comments. I must remember to use accessor methods and methods that I already have. As yet, I don't know anything about copying so I wait until it's discussed in the book.
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.