Oop intro, Encapsulation, Inheritance and Polymorphism(1.2.4 e) Flashcards

1
Q

What is a paradigm?

A

a way of thinking
a change of paradigm is a change in the way you think

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

Programming languages in paradigms

A

different programming languages live in different paradigms some live in multiple

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

What are classes?

A

templates that define the behaviour

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

What are objects?

A

manifestations (instance) of a class

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

What are the two main aspects of classes?

A

attributes
methods

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

What are attributes?

A

what data is stored and how it is stored (similar to variables)

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

What are methods?

A

how the class behaves (similar to subroutines)

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

What should you do before coding a class when designing it?

A

draw a diagram

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

What does private attribute/method mean?

A

that the given attribute or method cannot be accessed from outside the class definition

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

What does public attribute/method mean?

A

that the given attribute or method can be accessed from outside

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

What are getters?

A

retrieves the data from an attribute and returns it to the wider program
depending on the required behaviour can modify the output to match what the wider program needs

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

What are setters?

A

takes in a value from the wider program and modifies the relevant attributes accordingly
can include validation within the method meaning every time the attribute is modified the value is validated

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

Defining getters and setters

A

read only attribute only a get method is provided
are some basic methods we add to any class definition to enable access to attribute (as/when we need to)
generally good idea to add validation to prevent attributes being messed with improperly

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

What is encapsulation?

A

bundling data and methods together so the direct access to the data is unnecessary

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

What does encapsulation entail?

A

restricts access to attributes (declared private)
only way to access the attributes is through the methods (declared public)

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

Benefits of encapsulation

A

enforces data integrity
complex behaviour (e.g fancy validation) can be abstracted away and reused at will
increase program security

17
Q

Drawbacks of encapsulation

A

lots of boiler code
requires lengthy design work and planning (difficult to prototype functional oop)

18
Q

What is inheritance?

A

where we create a subclass of a class

19
Q

Parent/super class and child/sub class

A

parent/super class is the original class
child/sub class is the new class
child class inherit all the attributes and methods from the parent class
child class can have additional attributes and/or methods of its own
saves time as methods and attributes don’t need rewritten

20
Q

What is dynamic polymorphism?

A

where a method is defined in both the parent and child classes with the same name but different functionality

21
Q

What is static polymorphism?

A

wherre a method had different functionality depending upon the parameters passed to it

22
Q

Why polymorphism?

A

allows for programmers to use sensible self-documenting method names while having the flexibility to redefine these methods to better suit a child class

23
Q

Polymorphism super

A

can call methods from superclass using keyword super
this allows us to use methods from both superclass and the child class

24
Q

Polymorphism constructor

A

using the superclass method can be benificial especially when defining constructor of subclass
by invoking constructor of superclass and amending it we can reduce duplicate code and remove potential future maitenance issues
child/sub class method overridess parent/super class methods