Object Oriented Programming Flashcards

(14 cards)

1
Q

What is a class?

A

A class is a definition or blueprint of the fields (attributes) and methods (actions and functions) of an entity.

For example cats have a name, number of remaining lives, and colour (fields)
and they can meow, eat, and sleep (methods).

we may decide to model real world cats using a class.

Note that cats here is a general definition of a cat, not a specific cat.

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

What is an object?

A

An object is an instance of a class.

For example, if we have a class “Cat”, and instance of this class might have the name jerry, 2 more remaining lives, and the colour blue.

This cat can meow, eat, and sleep just like all cats, but its fields now have specific values that make it an individual.

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

What is encapsulation?

A

The fields of an instance should only be read or written by methods of that instances class.

That is, all fields should be kept private, where methods can be either public or privates.

To access the specific properties of an instance, you should use a method of the form get_property()

this is an important concept because if we allow the fields to be changed willy nilly, then odd things can happen. for example, a cat can only lose one life at a time, so we can clearly define a function that will reduce the number of remaining lives, rather than allow other programmers to reduce the number of lives by a silly amount,( such as 12)

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

What is abstraction?

A

Abstraction is the process of hiding aspects of the object that are outside the current scope. it is useful for organising complicated code that has many levels of things happening.

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

What is inheritance?

A

The concept of a class being able to use the fields and methods of an ancestor class. e.g. an animal can eat and sleep. a cat is a type of animal, and so it can eat and sleep as well. but it can do other things that are unique to cats, such as meow and purr.

sub-type = descendent
super-type = ancestor

parent and child are immediate only.

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

What is a Compositional Relationship?

A

A car is composed of many parts including a steering wheel, but it is not a type of steering wheel, and so it should not inherit from the steering wheel class.

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

What is Multiple Inheritance?

A

The ability to inherit from multiple classes.

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

What does it mean that objects are polymorphic?

A

x.foo() means that you have to look in the x class for method foo()

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

What are instance members?

A

fields and methods of an instance.

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

What are class members?

A

also called static fields or static methods. these are fields and methods that are accessible outside of an instance. please note that these are not really a part of OOP as they are more like normal variables and functions that are just under the namespace of a class, which is good, but not OOP :)

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

What is the constructor?

A

The method that sets up the instance of a class upon creation.

This can range from simply setting fields to default values to something far more complex like setting up a compute graph in tensor flow.

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

What is an interface?

A

A set of methods or actions that can be shared between otherwise unrelated classes. e.g. a cat and a fighter jet can both move and stop, but it doesn’t make sense for them to inherit from the same ancestor.

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

What is an abstract class?

A

A class that is not intended to be instantiated. It is only intended to be inherited.

E.g. mammal, we would probably instantiate as a cat rather than a mammal. but it is still useful (reusable code) to have it as an abstract class from which cat, dog, human, can inherit members.

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

What is prototypical inheritance?

A

A slightly different form of inheritance where inheritance is defined by links between objects, rather than formal classes. in practices, this results in very similar functionality to normal inheritance but a different syntax.

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