CPS 209 Lecture 1: Lecture 1 Inheritance And Polymorphism

180 views25 pages

Document Summary

It instructs us to never say anything twice in the same program. It states that every contingent truth about the behaviour of the program should be stated exactly in one place inside the program. Without it, if there are only classes used to express types it is hard to compare 2 problem domains to see if they are conceptually closer than another 2. Eg: problem domain concepts of hawk and sparrow are somehow conceptually closer to each other than problem domain concepts of hawk and planet. To write a polymorphic method: it is a method whose parameter type is a superclass. Without inheritance + static type checking this is not possible. // you could write two identical methods for separate birds. // but it would cause so much additional code (completely against our dry principle) void pluck(hawk h){ void pluck(sparrow h){ // so with inheritance we can make this 1 method! void foo (bird b){

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