30-evolutionofinterfaces

30-evolutionofinterfaces - The Evolution of Interfaces...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
The Evolution of Interfaces Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 — Lecture 30 — 12/10/09 © University of Colorado, 2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Credit where Credit is Due • Some of the material for this lecture is taken from “Programming in Scala” by Martin Odersky, Lex Spoon, and Bill Venners • as such some of this material is copyright © 2007, 2008 Odersky, Spoon and Venners • In addition, some material is taken from “Ruby For Rails” by David Black • as such some of this material is copyright © 2006 Manning Publications 2
Background image of page 2
Goals for this Lecture • Examine mechanisms in more recent OO languages for evolving the concept of “interface”, providing Fexibility in specifying the types of an application • Go (brieFy) • Clojure (brieFy) • Scala • Ruby • Wrap up the semester 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Review: (Lecture 3) Relationships: Interfaces • A class can indicate that it implements an interface • An interface is a type of class deFnition in which only method signatures are deFned • A class implementing an interface provides method bodies for each deFned method signature in that interface • This allows a class to play different roles, each role providing a different set of services • These roles are then independent of the class’s inheritance relationships • Other classes can then access a class via its interface • This is indicated via a “ball and socket” notation 4
Background image of page 4
Reminder (Lecture 4): Interface Example • Consider modifying the Animal hierarchy to provide operations related to pets (e.g. play() or takeForWalk()) • We have several options, all with pros and cons • add Pet-related methods to Animal • add abstract Pet methods to Animal • add Pet methods only in the classes they belong (no explicit contract) • make a separate Pet superclass and have pets inherit from both Pet and Animal • make a Pet interface and have only pets implement it • This often makes the most sense although it hinders code reuse • Variation: create Pet interface, but then create Pet helper class that is then composed internally and Pet’s delegate if they want the default behavior 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Reminder (Lecture 4): Animals (With Inheritance) Cat makeNoise() Tiger makeNoise() Rhino makeNoise() Animal sleep() Feline roam() Canine roam() Pachyderm roam() Wolf makeNoise() Wolf Dog makeNoise() Lion makeNoise() Elephant makeNoise() Hippo makeNoise() 6 Essentially, how do we make Dog and Cat be Pets without impacting the rest of the classes?
Background image of page 6
• Consider modifying the Animal hierarchy to provide operations related to pets (e.g. play() or takeForWalk()) • We have several options, all with pros and cons • add Pet-related methods to Animal • This approach is sub-optimal because non-Pet classes receive Pet behaviors via inheritance; you would be forced to override those behaviors to raise an exception for non-Pets. 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2010 for the course CSCI 5448 taught by Professor Anderson during the Fall '09 term at Colorado.

Page1 / 30

30-evolutionofinterfaces - The Evolution of Interfaces...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online