Polymorphic
Polymorphism (polymorphism) is a technique that allows you to set a parent object to be equal to one or more of his child objects, after which the parent object can operate differently depending on the attributes of the child object currently assigned to it. To put it simply, it is a sentence: A pointer to the parent class type is allowed to be assigned a pointer to the child class type. The ability of different objects to respond to the same message in their own way is called polymorphism. It means that the biological class (life) is-eat in the same way, that human beings belong to creatures, and that pigs belong to creatures, and that all inherit life and realize their eat, but the call is the only way to call each eat method. That is, different objects respond to the same message in their own way (in response to the Eat selector).
To achieve polymorphism, there are two ways, covering, overloading.
1) Overwrite: Refers to the practice of redefining the virtual function of the parent class by a subclass.
2) Overloading: means that multiple functions with the same name are allowed, and the parameter tables of these functions are different (perhaps the number of parameters is different, perhaps the parameter type is different, perhaps the two are different).
—————————— Zombie Practice ————————————
Created in the interface
-(void) Viewdidload {
[Superviewdidload];
Additional setup after loading the view, typically from a nib.
[Nstimerscheduledtimerwithtimeinterval:.2target:selfselector: @selector (Addzomb) UserInfo:nilrepeats:YES];
}
-(void) addzomb{
Zomb *Z1 = [[Zomballoc]initwithframe:cgrectmake (300, 100, 60, 90)];
[Self.view ADDSUBVIEW:Z1];
ZOMBB *z = [[Zombballoc]initwithframe:cgrectmake (300, 200, 60, 90)];
[Self.view Addsubview:z];
}
? Two zombies, and two zombies are two subclasses, create a parent class to allow two zombie events to inherit from the parent class, create three classes:
And to make two zombie speed different locations, so a variety to have their own characteristics.
IOS Learning Note Object-oriented polymorphic instance zombie Practice-Lan Yi Education