methods
instance method
the actions performed on the instance
eg
setting value
retrieving value
printing value
class method
applies to a class
eg
creating a new instance of a class
Subtopic 3
applying method can affect state of object
can apply same methods to different objects
a key concept
syntax
( ClassOrInstance method );
1st... left bracket
2nd... name of class or instance
3rd.... a space
4th... name of method
5th... closed off with right bracket
6th... semicolon to teminate
( receiver message );
different way to think about syntax format
ask to perform some action = sending "message" to class/instance
recipient is "reciever"
class or method
method is the message
example of applying a class method
send message to Car class (reciever)
asking to give new car
resulting object is stored in variable yourCar
class or factory method
example of instance method
actions on new car are instance methods
minus sign (-) is instance method
plus sign (+) is class method
object
thing
something that I want to do to a thing
instance of a class
each instance is an object
each object has unique characteristics
instance variable
has own set of instance variables
class car
object myCar
method drive it
method fill with gas
method wash it
method service it
create new class and object (3.2)
@interface section
does 3 things
describes class
describes class data components
describes class methods
Summary
to define a class - 3 things
tell compiler what "parent" class new class came from
specify data to be stored in objects of class
define type of operations (methods) that can be used with objects
Summary
@interface section general format
@interface example 3.2
what is this section called????????????
new class name Fraction
parent class NSObject
NSObject class defined in NSObject.h
NSObject.h included when import Foundation.h
memberDeclaration section
members declared are "instance variables"
specifies type of data stored in new class
specifies names of data types
closed in curly braces
this example has two "integer members" called numerator and denominator
Subtopic 4
displays value of the declared members
minus sign (-) means it's an instance method
Subtopic 3
@implementation section
contains the code that implements class methods
program section
contains program code
forming variable names
1. begin with letter or underscore
2. follow with letters, underscores, digits
"reserved words/name" not used
Appendix B for list
cannot start with number
no spaces
no invalid characters
upper/lower case sensitive
classes start with upper-case (by convention)
"AddressBook"
instance variables/objects start with lower-case
"currentEntry" or "current_entry"
methods start with lower-case
"addNewEntry"
upper-case inside names to start new word
readability
pick meaningful names
increase readability
good for debug/documentation phases
program more self-explanatory
Loading...