Class 11 – Intro to Classes
Agenda Check-in Lateral Thinking Warm-Up Issues and Questions Introducing Classes Built-in Classes Creating  and Using Classes Wrap-up, Project Work, Q&A Preparing for Mid-Term
Introducing Classes What is a Class? Objects and OOP/OOD An object represents a thing or entity Properties (state) Methods (behaviour) Rules & Procedures Why use classes? Abstraction, instantiation, code re-use Encapsulation, interface, API Inheritance, polymorphism
The Ball Class PROPERTIES Size Base_Color Elasticity Shape Decal? METHODS Roll Bounce Curve? Fly Spin
Classes in Ruby Built-in Classes http://ruby-doc.org/core/ Examples: Array, String, Matrix, Foo, Object Inheritance: see DateTime Note: all attributes and behaviours are treated as methods in Ruby (def) Custom Classes “ class” keyword Capitalize class name “ Get” and “set” methods Initialize with “new” method
A Class Act! class Myball def initialize end def bounce (val) val.times do puts "Ball bounces" end end def ballColor=(value) @color=value end def ballColor @color end end myBall=Myball.new myBall.bounce(3) x=rand(3) case x when 0 myBall.ballColor="red" when 1 myBall.ballColor="white" when 2 myBall.ballColor="blue" end puts myBall.ballColor
Wrap-up Summary Classes represent “things” Object Oriented Development models (or abstracts) attributes and behaviours into classes  Objects are instances of a Class Next Final Exam Wednesday Fishbone Diagram – Cause & Effect – Schedule? Assignments and project due at end of next week  (5pm Friday)