SlideShare a Scribd company logo
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)

More Related Content

PPTX
Greenfoot presentation
PPTX
OOP Basic Concepts
PDF
Object oriented programming With C#
DOC
C# by Zaheer Abbas Aghani
PPTX
Oops concepts
PPTX
Pi j3.1 inheritance
PDF
Beginning OOP in PHP
PPT
2. Basics of Java
Greenfoot presentation
OOP Basic Concepts
Object oriented programming With C#
C# by Zaheer Abbas Aghani
Oops concepts
Pi j3.1 inheritance
Beginning OOP in PHP
2. Basics of Java

What's hot (12)

PPT
Presentation on java
PPT
RIBBUN SOFTWARE
PPT
Introduction what is java
PPTX
Classes And Objects
PPTX
Object Oriented Programming
PDF
Reflection and Introspection
PPTX
Ruby OOP: Objects over Classes
PPTX
OOP->A Bird's-eye view
PPT
java-corporate-training-institute-in-mumbai
PPT
PDF
Object Oriented Programming : Part 2
PPT
Object oriented programming (oop) cs304 power point slides lecture 01
Presentation on java
RIBBUN SOFTWARE
Introduction what is java
Classes And Objects
Object Oriented Programming
Reflection and Introspection
Ruby OOP: Objects over Classes
OOP->A Bird's-eye view
java-corporate-training-institute-in-mumbai
Object Oriented Programming : Part 2
Object oriented programming (oop) cs304 power point slides lecture 01
Ad

Similar to Class 11 lecture notes (20)

PPTX
Is2215 lecture2 student(2)
PPTX
OOPs in Java
PPTX
Moo the universe and everything
PPT
Objected-Oriented Programming with Java
PPTX
Presentation on Object and classes in OOP.pptx
PDF
Core java and advance java syallabus - Cacit.co.in
PPT
Ruby On Rails
PDF
Take the Plunge with OOP from #pnwphp
PDF
OOP in PHP
ODP
A Tour Of Scala
PPTX
Php meetup 20130912 reflection
PPTX
Core java online training
DOCX
Java se 8 fundamentals
PPTX
OOP Day 2
PPT
PHP-05-Objects.ppt
KEY
Static or Dynamic Typing? Why not both?
PPSX
Core java lessons
PDF
Me, my self and IPython
DOCX
Ravi software faculty
PDF
09. Ruby Object Oriented Programming - Ruby Core Teaching
Is2215 lecture2 student(2)
OOPs in Java
Moo the universe and everything
Objected-Oriented Programming with Java
Presentation on Object and classes in OOP.pptx
Core java and advance java syallabus - Cacit.co.in
Ruby On Rails
Take the Plunge with OOP from #pnwphp
OOP in PHP
A Tour Of Scala
Php meetup 20130912 reflection
Core java online training
Java se 8 fundamentals
OOP Day 2
PHP-05-Objects.ppt
Static or Dynamic Typing? Why not both?
Core java lessons
Me, my self and IPython
Ravi software faculty
09. Ruby Object Oriented Programming - Ruby Core Teaching
Ad

More from Stephen Parsons (19)

PPTX
Atlantic Woodworkers Website Strategy
PPTX
Chairs Report to LSCRS 2012 AGM
PPT
Class 10 Arrays
PPT
Program Renewal for NSCC Schools 2010-11
PPT
Class 7 lecture notes
PPTX
Class 6a ruby math
PPTX
Class 6 truth tables and boolean math
PPTX
Class 5 - Set Theory and Venn Diagrams
PPTX
Class 4 IPO and Intro to Ruby
PPTX
Class 3 Binary & Hexadecimal
PPTX
Class 2 Math I
PPT
Class 1 introduction to logic & problem solving
PPTX
Portfolio Of A Community
PPT
Cause & effect analysis part 2
PPT
Cause & effect analysis part 1
PPT
Class 10 Lecture Notes
PPT
Class 9 Lecture Notes
PPT
Class 8 Lecture Notes
PPT
Deck Project Phase II
Atlantic Woodworkers Website Strategy
Chairs Report to LSCRS 2012 AGM
Class 10 Arrays
Program Renewal for NSCC Schools 2010-11
Class 7 lecture notes
Class 6a ruby math
Class 6 truth tables and boolean math
Class 5 - Set Theory and Venn Diagrams
Class 4 IPO and Intro to Ruby
Class 3 Binary & Hexadecimal
Class 2 Math I
Class 1 introduction to logic & problem solving
Portfolio Of A Community
Cause & effect analysis part 2
Cause & effect analysis part 1
Class 10 Lecture Notes
Class 9 Lecture Notes
Class 8 Lecture Notes
Deck Project Phase II

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
master seminar digital applications in india
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Lesson notes of climatology university.
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Pre independence Education in Inndia.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Insiders guide to clinical Medicine.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharma ospi slides which help in ospi learning
PDF
Complications of Minimal Access Surgery at WLH
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O7-L3 Supply Chain Operations - ICLT Program
Pharmacology of Heart Failure /Pharmacotherapy of CHF
master seminar digital applications in india
Basic Mud Logging Guide for educational purpose
Lesson notes of climatology university.
human mycosis Human fungal infections are called human mycosis..pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Pre independence Education in Inndia.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
102 student loan defaulters named and shamed – Is someone you know on the list?
Insiders guide to clinical Medicine.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharma ospi slides which help in ospi learning
Complications of Minimal Access Surgery at WLH
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
01-Introduction-to-Information-Management.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Class 11 lecture notes

  • 1. Class 11 – Intro to Classes
  • 2. 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
  • 3. 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
  • 4. The Ball Class PROPERTIES Size Base_Color Elasticity Shape Decal? METHODS Roll Bounce Curve? Fly Spin
  • 5. 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
  • 6. 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
  • 7. 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)

Editor's Notes

  • #2: This evening’s class will start with a brief introduction to classes, a concept central to the notion of object-oriented programming. By the time we have finished this class you will have examined concepts related to object-oriented programming and be able to articulate the meaning and utility of classes in programming.
  • #3: Our agenda is a short one:
  • #4: We will begin our discussion on classes with an exploration of object-oriented development, an approach to programming that starts by dealing with entities in the code as “objects” that can be manipulated and examined like objects in the real-world. Our code so far has been fairly simple, but at the same time quite verbose – that is, we have had to write a lot of code – often repeatedly – in order to get our solutions to work. We have learned that some techniques like branching, looping and the development of methods can allow us to write more elegant (or tighter) code. OOD allows us to go a step further by modelling real-world objects so that we can use them more effectively. A Class in programming terms is the model of an object: something that represents a thing and can describe properties or attributes of the object as well as the tings it can do – its methods or behaviours. For example, if we wanted to develop a game in which we needed to model a car, we would need to describe the object with the properties as well as the actions that the car can undertake. So how do we describe a car? What are its attributes? [type, model, maker, ext_color, int_color, style, engine_size, hp, warranty, int_fabric]. And what can a car do [drive, backup, accelerate, park] Class creation and manipulation requires certain rules and procedures and those are largely determined by the language. Ruby is a very simple yet robust language that minimizes the rules and procedures needed to create and manipulate its Classes. In addition, Ruby has many built-in classes – some of which we will examine shortly. These built-in classes are part of the default set of capabilities that the language is able to work with and in fact that we have already been working with since the beginning of our work in Ruby. Why use classes? To begin, being able to abstract – or model – an object as a Class allows us to use it as a blueprint or cookie-cutter so we can create numerous instances of the object and manipulate its properties and behaviours. This allows us to re-use the code many times rather than having to write it every time we want to use an object in our code. Second, as a developer if I write a piece of code and want to re-sell that application, I can encapsulate the class into an encrypted object like a java .jar file or a Windows .dll and hide the details of the code that makes it work – protecting my investment and my intellectual property. If I want to use someone else’s class I may be able to simply attach the class to my application and call its properties and methods by following a published API (application programming interface). The API tells us what I can pass to the object and what I will get back from it…I don’t really need to know what’s inside of it. Finally, I can create classes based on other classes – so that if I need to have an object that is like some other object, but has some unique capabilities or features, I can create a Class based on another (its parent) and then just add the additional properties or functions to it. I can also use functions that are in one class across numerous classes through something called polymorphism – as long as I follow some basic rules. Overall, then, Classes allow me to create a model of a business object and deploy or re-use instances of that object that I can manipulate in code. Let’s try an example: let’s think about the idea of a ball. I want you to write down two columns for our class “Ball”. What are all the things that describe a ball (the features that might make one ball different from or similar to another ball) and what are the things a ball can do (something that all balls may be made to do)…
  • #5: Well here’s the start of a model or abstraction of the Ball Class. The basic attributes might include…(see image) And the basic behaviours could include…(see image) What else did you identify? Are they features of ALL Balls? Now if we instantiate the class Ball by creating a new Ball, then that object should be able to be described by any of those properties and should be able to do any of those methods. If we wanted to create a new class of ball – say Soccer_Ball, then what new properties and methods might we need to add?
  • #6: Let’s look at some of the built-in classes in Ruby – you can point your browser to the URL shown here and explore some of the Classes in Ruby. We’ve used some of these Classes already, most recently Array – let’s look at that…note the methods listed for the Class “Array” Now look at some others – here are some ideas that might be useful: String, Matrix, Foo (don’t ask), and how about Object! Object is the Mother of ALL Classes in Ruby, so that means that everything that Object can do, every other Class can do too. Looking at parent  child relationships, you can see the inheritance in something like DateTime Class – which is a child of Date. We can develop our own classes based on those classes simply by creating a sub-class…or we can create our own class by using the class keyword, capitalizing the class name and defining the properties and methods of the class – remember that to Ruby both properties and behaviours are all methods, but properties are just laid out to allow us to set the value of a property and to get the value of the property (we’ll see this in a moment when I demonstrate a class in Ruby). Finally, to use the Class – you use the “new” keyword to create a copy of the object and then you are off to the races! Let’s see an example.
  • #7: In this example, we’ll code the Class Ball and create a ball Color property and a bounce method. Follow along if you can. Initialize is a useful function that is run automatically when the object of the class is created. Although initialize can be left out, it is a good idea to add it in, even if it does nothing more than set the object up. You can use initialize to set up the default properties of the object. The left side is the creation of the Class, the right shows some code we can use to work with the class…we start by creating an instance of the Class using new and then we can do anything that is defined in the class – set the color, get the color, and bounce the ball. Note that when we ask the ball to bounce we tell it the number of times we want it to bounce and it does so. In the next section, I call a random function to set the color of the ball and then I print out the color of that particular ball. If I decided to create a second and third ball, they might be different colors – but each one would keep that property unless we change it.
  • #8: So for this course, we will not really need to get you developing Classes to any great extent. Our purpose was really to get you familiar with the notion of object-oriented programming and development and to understand a little about how classes work and how you might create and use a class. I don’t suggest that you should create and use Classes in your project or assignment, but you are free to do so if you think you want to. OOP is a subject you would undertake in some detail at the next level or programming such as in our PROG 1040 Programming I or many of our courses in Programming and Web Concentrations. In our next session we are going to look at a technique to evaluate cause and effect in business or workplace situations using a tool called a Fishbone Diagram