
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
16 questions
Bài 1: Làm quen với MS_Excel 2016
Presentation
•
11th Grade
19 questions
Operadores de Búsqueda, TIC. Quinto Bach.
Presentation
•
12th Grade
16 questions
El Poder de PowerPoint-Javier
Presentation
•
KG
18 questions
Blood Types
Presentation
•
12th Grade - University
13 questions
Present and Past Tenses
Presentation
•
12th Grade
17 questions
NOTASI FAKTORIAL
Presentation
•
12th Grade
16 questions
Central Bank
Presentation
•
11th Grade
18 questions
หลักการเขียนโปรแกรม1_ุ64 สัปดาห์ที่ 5
Presentation
•
11th Grade
Popular Resources on Wayground
15 questions
Grade 3 Simulation Assessment 1
Quiz
•
3rd Grade
22 questions
HCS Grade 4 Simulation Assessment_1 2526sy
Quiz
•
4th Grade
16 questions
Grade 3 Simulation Assessment 2
Quiz
•
3rd Grade
19 questions
HCS Grade 5 Simulation Assessment_1 2526sy
Quiz
•
5th Grade
17 questions
HCS Grade 4 Simulation Assessment_2 2526sy
Quiz
•
4th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
24 questions
HCS Grade 5 Simulation Assessment_2 2526sy
Quiz
•
5th Grade
20 questions
Math Review
Quiz
•
3rd Grade
Discover more resources for Computers
20 questions
Earth Day Trivia
Quiz
•
9th - 12th Grade
10 questions
Earth Day Awareness and Impact
Interactive video
•
6th - 12th Grade
5 questions
A.F/ST Quizizz Day 1
Quiz
•
9th - 12th Grade
100 questions
Biology EOC Review
Quiz
•
9th - 12th Grade
20 questions
Earth Day
Quiz
•
3rd - 12th Grade
16 questions
AP Biology: Unit 1 Review (CED)
Quiz
•
9th - 12th Grade
5 questions
G.PC/DF Quizizz Day 2
Quiz
•
9th - 12th Grade
20 questions
verbos reflexivos en español
Quiz
•
9th - 12th Grade