CS246 Lecture Notes - Lecture 8: Idiom, Iterator, Code Reuse

41 views20 pages

Document Summary

One or more subscriber/observer classes - receive data and react to it. Special method to create objects instead of using the constructor. Write a video game with 2 kinds of enemies, turtles and bullets. The system will randomly send out enemies, but bullet becomes more freque. We never know exactly what enemy will be generated. This means we can"t u class level { public: virtual *enemy createenemy() = 0; // factory method - class normal: public level { public: //create turtles more often equent when you get to higher levels n"t use the turtle/bullet constructors directly. method - creates enemies class castle: public level { public: Suppose we add another enemy boss type: king rice soup. Only one - every time king rice soup appears, it is the same one. Normal level will never create king rice soup, while castle levels will createenemy() can produce a new enemy or the singleton boss instance.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers