lec23 - # Dan Grossman, CSE341 Spring 2008, Lecture 23 #...

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

View Full Document Right Arrow Icon
# Dan Grossman, CSE341 Spring 2008, Lecture 23 # Multiple inheritance, Interfaces, Mixins # class Pt attr_accessor :x, :y def distToOrgin Math.sqrt(x * x + y * y) end end e class ColorPt < Pt attr_accessor :color def darken self.color = "dark " + self.color end end e class Pt3D < Pt attr_accessor :z def distToOrgin Math.sqrt(x * x + y * y + z * z) end end e class ColorPt3D_1 < ColorPt attr_accessor :z def distToOrgin Math.sqrt(x * x + y * y + z * z) end end e class ColorPt3D_2 < Pt3D attr_accessor :color def darken self.color = "dark " + self.color end end e # This does not exist in Ruby (or Java, it does in C++) # class ColorPt3D_3 < ColorPt, Pt3D # end # class Person attr_accessor :height, :weight attr_accessor :pocket def show_your_pocket @pocket.each { |x| puts x } end end e class Cowboy < Person def initialize self.pocket = ['gun', 'bullets'] end def draw # . .. something to do with shooting gun end end e
Background image of page 1

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

View Full DocumentRight Arrow Icon
class Artist < Person def initialize self.pocket = ['paint', 'brushes'] end def draw
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

lec23 - # Dan Grossman, CSE341 Spring 2008, Lecture 23 #...

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

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