
F6-CS OOP
Presentation
•
Computers
•
12th Grade
•
Practice Problem
•
Medium
Adrien Ebitner
Used 3+ times
FREE Resource
20 Slides • 2 Questions
1
Object Oriented Programming
2
What is OOP?
method of structuring a program
using individual objects
think of it like components of a system
an object contains data
3
What is OOP?
is a programming paradigm (way to classify programming language based on)
strucutre like objects
For e.g. an object could represent a person
with properties like name, age, address
behaviors such as walking, talking, breathing, etc.
4
Objectives
Create a class
using class to create new objects
model systems with class inheritance
5
Class
why do we need classes?
sometimes we need classes for many reasons
remember list in Python?
look at this list
pikachu = [electric, ground, [electric, fly, steel], 35, 55, 40, 50, 50, 90]
many issues
6
Class
pikachu = [electric, ground, [electric, fly, steel], 35, 55, 40, 50, 50, 90]
when the list gets long, will you remember the element with index 5 mean?
what if you have another list but, it is shorter?
it is too inconsistent
7
How to Define a Class
class Dog:
pass
usually PascalCase
8
9
How to Define a Class
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
__init__ is an intance method that initializes a newly created object. It takes the object as its first argument followed by additional arguments.
10
How to Define a Class
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
attributes created in .__init__() are called instance attributes. Meaning all Dog objects have a name and an age, but the values may vary
11
adding class attributes
class Dog:
# Class attribute
species = "Canis familiaris"
def __init__(self, name, age):
self.name = name
self.age = age
12
adding class attributes
class Dog:
# Class attribute
species = "Canis familiaris"
Class attributes are different, where all class attributes are directly beneath the first line of the class name. All class instances will have the same value for class attributes.
13
to create instance
buddy = Dog("Buddy", 9)
miles = Dog("Miles", 4)
These create two new Dog instances
Why we don't need 3 arguments?
When creating a new instance, python will pass the instance to the first paramter of .__init__()
14
15
to create instance
You can change the different instance's attribute's value
>>buddy.age = 10
>>buddy.age
10
>>miles.species = "Felis silvestris"
>>miles.species
'Felis silvetris'
16
Fill in the Blanks
17
Fill in the Blanks
18
Inheritance
A process by which the methods and data from one class, superclass or base class, are copied to another class, a derived class
19
to create method
Write a short program to declare a class, student, with the private attributes name, dateOfBirth and examMark, and the public method displayExamMark. Declare an object myStudent, with a name and exam
mark of your choice, and use your method to display the exam mark.
20
Inheritance
21
Inheritance
22
Exercise
Object Oriented Programming
Show answer
Auto Play
Slide 1 / 22
SLIDE
Similar Resources on Wayground
17 questions
Small Conversation Part 1
Presentation
•
12th Grade
16 questions
ความรู้เบื้องต้น Microsoft PowerPoint
Presentation
•
12th Grade
17 questions
Formularios en HTML
Presentation
•
12th Grade
16 questions
Review Text Bahasa Inggris Peminatan
Presentation
•
12th Grade
17 questions
G12Q2W1L1- Digital Rights and Responsibilities
Presentation
•
12th Grade
20 questions
Get Smart Plus 3 Topic 8 was/were
Presentation
•
1st - 4th Grade
20 questions
One Step Equations
Presentation
•
KG - University
15 questions
CAI 711 - Week 4 P1
Presentation
•
12th Grade
Popular Resources on Wayground
10 questions
GPA Lesson
Presentation
•
9th - 12th Grade
7 questions
Albert Einstein
Quiz
•
3rd Grade
31 questions
Bridge A Review
Quiz
•
3rd Grade
6 questions
Blue Sue and Red Ruth
Quiz
•
3rd Grade
8 questions
(Day12 HW) Inverse Trig Ratios
Quiz
•
9th Grade
20 questions
Summer Geometry QUIZ (Week3)
Quiz
•
9th Grade
16 questions
Theme Practice
Quiz
•
7th Grade
20 questions
Taxes
Quiz
•
9th - 12th Grade