Classes, Object-Oriented Programming and Inheritance Flashcards

1
Q

What is an Object?

A

An object is an instance of a type - Everything in python is an option!

  • each object has a type
  • an internal data representation
  • an interface for interacting with the object
    i. e. 1234 is an instance of a type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the advantages of Object Oriented Programming?

A
  • Bundle data into packages together with procedures that work on them through well defined interfaces
  • divide and conquer development
    • -> implement and test behavior of each class separately
  • classes make it easy to reuse code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do you have to do to create a class?

A
  1. Define the class name (=type i.e. student)
  2. Define class attributes (what is the object?)
  3. Define methods (How to use the objects?)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do you have to do to use the class?

A
  1. Create a new instance of a class (class objects)

2. Do operations on these instances

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What do you use the self for?

A
To refer to some instance while defining the class i.e. 
class Coordinate (object): 
(self.x - self.y) ** 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the main difference between a class and one of its objects?

A
A class defines data and methods across all instances 
vs.
An instance has the structure of the class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are data attributes within a class?

A

They represent your object with data
i.e. for an animal: age, name
for a coordinate: x and y values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are procedural attributes within a class?

A

Methods (Behaviour/operations)

  • -> How you can interact with an object of the class, what it does
    i. e. for a coordinate: find distance between two
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are getter and setter methods used for?

A

Should be used outside the class to access data attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the dot notation used for with objects?

A

the dot is used to access attributes(data and methods)

but use primarily for methods and use getters and setters for data attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly