Class 11 lecture notes
-
Upload
stephen-parsons -
Category
Education
-
view
439 -
download
2
description
Transcript of Class 11 lecture notes
![Page 1: Class 11 lecture notes](https://reader033.fdocuments.in/reader033/viewer/2022061120/546cacfdaf795985298b50bc/html5/thumbnails/1.jpg)
Class 11 – Intro to Classes
![Page 2: Class 11 lecture notes](https://reader033.fdocuments.in/reader033/viewer/2022061120/546cacfdaf795985298b50bc/html5/thumbnails/2.jpg)
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
![Page 3: Class 11 lecture notes](https://reader033.fdocuments.in/reader033/viewer/2022061120/546cacfdaf795985298b50bc/html5/thumbnails/3.jpg)
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
![Page 4: Class 11 lecture notes](https://reader033.fdocuments.in/reader033/viewer/2022061120/546cacfdaf795985298b50bc/html5/thumbnails/4.jpg)
The Ball Class
PROPERTIESSizeBase_ColorElasticityShapeDecal?
METHODSRollBounceCurve?FlySpin
![Page 5: Class 11 lecture notes](https://reader033.fdocuments.in/reader033/viewer/2022061120/546cacfdaf795985298b50bc/html5/thumbnails/5.jpg)
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
![Page 6: Class 11 lecture notes](https://reader033.fdocuments.in/reader033/viewer/2022061120/546cacfdaf795985298b50bc/html5/thumbnails/6.jpg)
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
![Page 7: Class 11 lecture notes](https://reader033.fdocuments.in/reader033/viewer/2022061120/546cacfdaf795985298b50bc/html5/thumbnails/7.jpg)
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)