Lecture 3 Flashcards

1
Q

Object Oriented Design Principles

A
  1. Encapsulation
  2. Abstraction
  3. Inheritance
  4. Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Encapsulation

A

Grouping related variables and function to reduce complexity and increase reusability.
Classes/Objects.

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

Abstraction

A

Hide details and show the essentials. Isolate the impact of changes.
Private helper methods. Only interactable with public methods. Use interfaces to group related methods together.

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

Inheritance

A

Eliminate redundant code.
Superclasses and subclasses.
Remember, subclasses inherit all public/protected attributes and methods from their superclass.

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

Polymorphism.

A

Refactor ugly if and switch/case statements.

2 kinds of polymorphism.
Static (compile time): Method overloading.
Dynamic (runtime): Method overriding through inheritance.

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

Substitution principle.

A

States that you can always use a subclass when a superclass object is expected.

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

Polymorphism benefits.

A

Method calls are always determined by the type of the object, not the variable containing the object reference.
This is dynamic method lookup. Lets us treat objects of different classes in a uniform way.
This is polymorphism. Ask multiple objects to carry out a task, and they each do so in their own way.

This makes programs easily extendable.

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

What is an interface? What are the benefits?

A

A group of related methods with empty bodies. This lets us program uniformly with an interface type.
The implementation is deferred to subclasses.

Helps with program modification and extension.

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

Subclasses inherit…

A

Data and behavior from its superclass.

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

What is an abstract class?

A

Concrete classes can be instantiated.

Objects with abstract methods cannot be instantiated. But a reference variable whose type is an abstract class can be declared.

The object it refers to must be an instance of an concrete class.

Allows polymorphisms based on an abstract class.

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

When can a subclass be used in place of a superclass?

A

Always.

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

Can subclasses override methods defined in the superclass?

A

Yes, it can be overridden and reimplemented.

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