Date post: | 31-May-2015 |
Category: |
Technology |
Upload: | michael2008s |
View: | 2,905 times |
Download: | 2 times |
HistoryBrad 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
@interface NSObject <NSObject> { Class isa;
}
What is an Object ?
struct NSObject { Class isa;
}
Sunday, October 30, 2011
What is an Object ?@interface MyName : NSObject {
NSString *firstName;NSString *lastName;
}
struct MyName {
NSString *firstName;NSString *lastName;
}
Class isa;
Sunday, October 30, 2011
What is an Object ?NSObject
isa0
MyNameisa
firstNamelastName
048
NSObjectisa0
4 foobar
MyNameisa
firstNamelastName
048
MyNameisa
firstNamelastName
04812
foobar
Sunday, October 30, 2011
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;
typedef struct objc_class *Class;
/usr/include/objc/runtime.h
Sunday, October 30, 2011
MyName(instance)
MyName(Class)
MyName(MetaClass)
NSObject(Class)
NSObject(MetaClass)
isa
isa
super
super
super
isa
isasuper
isa
Object Model
Sunday, October 30, 2011
isa-swizzling
MyName(instance)
MyName(Class)
isa
HerName(Class)
isa
MyName *myName = [MyName alloc] init];
myName->isa = [HerName class];
Sunday, October 30, 2011
isa-swizzlingKey-Value Observing
State Machine
......
NSZombie
Sunday, October 30, 2011
Where the Objects Come From
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.
<<Squeak, Open Personal Computing and Multimedia>>
Object is a metaphor of cell.
Sunday, October 30, 2011
MessagingSmalltalk 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
MessagingSelector
typedef struct objc_selector *SEL;
IMPtypedef id (*IMP)(id, SEL, ...);
id
typedef struct objc_object { Class isa;} *id;
Sunday, October 30, 2011
Messaging@implementation MyName
- (void)printName:(NSString *)name{
......}
@end
void - [MyName printName:](id self, SEL _cmd, NSString *name){
......}
Sunday, October 30, 2011
Messaging [name printName:@”lldong”];
objc_msgSend(name, @selector(printName:), @”lldong”);
Sunday, October 30, 2011
Messaging
id objc_msgSend(id receiver, SEL name, arguments...){ IMP function = Class_getMethodImplementation(receiver->isa, name); return function(arguments);}
IMP class_getMethodImplementation(Class cls, SEL name);
- (IMP) methodForSelector:(SEL)sel;
Sunday, October 30, 2011
MyName(instance)
MyName(Class)
MyName(MetaClass)
NSObject(Class)
NSObject(MetaClass)
isa
isa
super
super
super
isa
isasuper
isa
Sunday, October 30, 2011
Messaging
- (void)forwardInvocation:(NSInvocation *)invocation
+ (BOOL)resolveInstanceMethod:(SEL)sel+ (BOOL)resolveClassMethod:(SEL)sel
- (id)forwardingTargetForSelector:(SEL)sel
1
2
3
Sunday, October 30, 2011
Conclusion
NO MAGIC
Sunday, October 30, 2011
Q & A
allContents
Sunday, October 30, 2011