CPS 209 Lecture 1: Lecture 1 Inheritance And Polymorphism

181 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+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents