Dynamic Binding In Objective C
Before going to this tutorial I come up with suggestion that
read my previous tutorial of Polymorhism
Wanna Read Link is here:Polymorphism in Objective C
Let come to this tutorial of Dynamic Binding. Dynamic
Binding as name suggests it include message or method at run time. Compiler
does not know information of invoking about it. Already Objective C invoke method
at run time or dynamically.
In other words it can said that Dynamic Binding power the
Polymorphism.
Example: Below is simple program you can expand your knowledge.
In Student.h
@interface Student:NSObject
{
NSString *studentname;
}
@property(nonatomic,strong)NSString *StudentName;
@property(nonatomic,strong)NSString *StudentName;
-(void)getStudentName:(NSString *)StudentName;
-(void)printName;
@end;
In Student.m
@implementation Student
@synthesize StudentName=_StudentName;
-(void)getStudentName:(NSString *)StudentName
{
studentname=StudentName;
}
-(void)printName
{
NSLog(@”The name of student is:%@”,studentname);
}
@end
In Teacher.h
@interface Teacher:NSObject
{
NSString *teachername;
}
@propertyonatomic,strong)NSString *TeacherName;
@propertyonatomic,strong)NSString *TeacherName;
-(void)getTeacherName:(NSString *)TeacherName;
-(void)printName;
@end;
In Teacher.m
@implementation Teacher
@synthesize TeacherName=_TeacherName;
@synthesize TeacherName=_TeacherName;
-(void)getTeacherName:(NSString *)TeacherName;
{
teachername=TeacherName;
}
-(void)printName
{
NSLog(@”The name of Teacher is:%@”,teachername);
}
In main section
Int main(int argc, const *argv[])
{
NSAutorealesePool *pool=[[NSAutorealesePool alloc]init];
Student student1=[[Student alloc]init];
[student1 getStudentName:@”abc”];
Teacher teacher1=[[Teacher alloc]init];
[teacher1 getTeacherName:@”Suraj”];
NSArray *ComputerScience=[[NSArray
alloc]initWithObjects:student1,teacher1,nil];
Id *computerscience1=[ComputerScience objectAtIndex:0];
[computerscience1 printStudentName];
Id *computerscience2=[ComputerScience objectAtIndex:1];
[computerscience2 printName];
Return 0;
}
In above program after creating array checking of object for
method is done at run time with appropriate content is printed.
I write this tutorial after keeping in mind you know already about id data type.
If you want to study about it click here : id data type
I write this tutorial after keeping in mind you know already about id data type.
If you want to study about it click here : id data type
I hope you like my tutorial.If any kind of query after
reading this tutorial in you mind you can comment here and can mail me.
I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in IOS development, kindly contact us http://www.maxmunus.com/contact
ReplyDeleteMaxMunus Offer World Class Virtual Instructor led training on IOS development . We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
For Demo Contact us:
Name : Arunkumar U
Email : arun@maxmunus.com
Skype id: training_maxmunus
Contact No.-+91-9738507310
Company Website –http://www.maxmunus.com
This comment has been removed by the author.
ReplyDelete