2. History
Brad Cox, Tom Love, 1981, ITT Corp.
Reusability & Backward Compatibility with C
Smalltalk + C = Object-Oriented Pre-Compiler
Objective-C, StepStone
1988, NeXT, AppKit & Foundation Kit
Sunday, October 30, 2011
3. What is an Object ?
@interface NSObject <NSObject> {
Class isa;
}
struct NSObject {
Class isa;
}
Sunday, October 30, 2011
4. What is an Object ?
@interface MyName : NSObject {
NSString *firstName;
NSString *lastName;
}
struct MyName {
Class isa;
NSString *firstName;
NSString *lastName;
}
Sunday, October 30, 2011
5. What is an Object ?
NSObject NSObject
0 isa 0 isa
4 foobar
MyName
0 isa MyName
4 firstName 0 isa
8 lastName 4 firstName
foobar
8 firstName
lastName
12 lastName
Sunday, October 30, 2011
6. /usr/include/objc/runtime.h
typedef struct objc_class *Class;
struct objc_class {
Class isa;
#if !__OBJC2__
Class super_class OBJC2_UNAVAILABLE;
const char *name OBJC2_UNAVAILABLE;
long version OBJC2_UNAVAILABLE;
long info OBJC2_UNAVAILABLE;
long instance_size OBJC2_UNAVAILABLE;
struct objc_ivar_list *ivars OBJC2_UNAVAILABLE;
struct objc_method_list **methodLists OBJC2_UNAVAILABLE;
struct objc_cache *cache OBJC2_UNAVAILABLE;
struct objc_protocol_list *protocols OBJC2_UNAVAILABLE;
#endif
} OBJC2_UNAVAILABLE;
Sunday, October 30, 2011
7. isa
super super
NSObject isa
(MetaClass)
isa
Object Model NSObject super
(Class)
super
MyName
(MetaClass)
isa
MyName
(Class)
MyName isa
(instance)
Sunday, October 30, 2011
8. isa-swizzling
HerName MyName *myName = [MyName alloc] init];
(Class)
myName->isa = [HerName class];
isa
MyName
(Class)
MyName isa
(instance)
Sunday, October 30, 2011
9. isa-swizzling
Key-Value Observing
NSZombie
State Machine
......
Sunday, October 30, 2011
10. Where the Objects Come From
<<Squeak, Open Personal Computing and Multimedia>>
Object is a metaphor of cell.
The complexity is handled through each object performing its
own functions, without undue interference from others.
The robustness comes from the fact that the loss of an
object does not damage other objects.
Supporting growth comes from using the same structuring and
communication mechanism throughout.
Finally, the reuse comes from each object performing its own
role, with only minimal connections to other objects.
Sunday, October 30, 2011
11. Messaging
Smalltalk is not only NOT its syntax or the class
library, it is not even about classes.
I'm sorry that I long ago coined the term "objects"
for this topic because it gets many people to focus
on the lesser idea.
The big idea is "messaging".
---- Alan Kay
Sunday, October 30, 2011
12. Messaging
Selector
typedef struct objc_selector *SEL;
IMP
typedef id (*IMP)(id, SEL, ...);
id
typedef struct objc_object {
Class isa;
} *id;
Sunday, October 30, 2011
15. Messaging
IMP class_getMethodImplementation(Class cls, SEL name);
- (IMP) methodForSelector:(SEL)sel;
id objc_msgSend(id receiver, SEL name, arguments...)
{
IMP function = Class_getMethodImplementation(receiver->isa, name);
return function(arguments);
}
Sunday, October 30, 2011
16. isa
super super
NSObject isa
(MetaClass)
isa
NSObject super
(Class)
super
MyName
(MetaClass)
isa
MyName
(Class)
MyName isa
(instance)
Sunday, October 30, 2011