CS 2110 Lecture Notes - Lecture 7: Abstract Data Type, Abstract Type

20 views4 pages

Document Summary

Whe(cid:374) usi(cid:374)g a gui, a shape"s positio(cid:374) is gi(cid:448)e(cid:374) (cid:271)y the top left (cid:272)or(cid:374)er of the box it can be inscribed in. We do(cid:374)"t like the (cid:272)reatio(cid:374) of shape objects. The abstract prevents the user from using the shape. If you tried to call the constructor you get a static error. We can call the constructor and run into problems. So this forces the user to construct objects of the right type. Suppose we have in the abstract class shape a sumareas() method. This would involve taking a list of. Shapes and adding the area of each of them. If we called a helper function for each shape, we get a problem: Because the sumareas method is defined in shape but the area method is not, it will not use the bottom up rule. We make an area method in shape. Now it will go down the chain and use the bottom up rule for the correct shape.

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

Related Documents