OOP Flashcards

Week 1.7 (14 cards)

1
Q

objects

A

instances of a class

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

class

A

objects characterised by the same attributes & behaviour

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

3 special methods

A
  1. __init__
  2. __str__ & __repr
  3. __len__
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

__init__

A

constructor method

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

__str__

A
  • str() on an object
  • more readable & user-friendly
  • targeted for end-users
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

__repr__

A
  • repr() on an object
  • more detailed
  • used for debugging & logging
  • targeted for developers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what are the 2 types of instance relationships

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

association relationship

A

for general relationship describing when one class uses the functionalities provided by another class

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

composition relationship

A

for the relationship between a whole thing & its component parts

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

why do we use inheritance

A
  1. model an ‘is a kind of’ relationship
  2. subclasses can add more fields & methods or make changes to existing methods in the parentclass to extend behaviour
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

when should we not use inheritance

A

just as a way of sharing fields & methods between classes

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

syntax for inheritance

A

class subClass(SuperClass)

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

superclass vs subclass

A
  • subclasses can override methods from superclass to provide specific functionality
  • when a method with the same name were defined in both superclass & a subclass, use super() to refer to method in superclass
  • using super to reuse initialisation and other superclass’ methods helps avoid repeating code across classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly