IOS Learning Note Object-oriented polymorphic instance zombie Practice-Lan Yi Education

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.