Lecture 6 - OOP Concepts Flashcards

1
Q

What concept encloses the data and functions that operate on that data into a single unit, the class?

A

Encapsulation

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

TF: Hiding private details from the outside world is an example of encapsulation

A

True

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

TF: Encapsulation allows external code to directly access class details without the use of predefined methods

A

False. They provide methods that allow users to access/modify it (i.e. no direct access)

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

What concept separates interface of a class from its implementation and focuses on the interface?

A

Abstraction

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

Hiding implementation details of a class and only presenting a clean and easy-to-use interface via class’ member function is an example of…

A

Abstraction

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

What does isolating the impact of changes made to the code mean regarding Abstraction?

A

Means changes to internal implementation doesn’t affect how users/programs interact with the interface (i.e. changing internal implementation doesn’t affect how users/programs interact with it)

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

What is meant by Black-box system in Abstraction?

A

System where internal workings or implementation details are hidden from the user (user can only interact with it through input, output)

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

What is Inheritance in programming?

A

Concept where classes can be organized into hierarchies allowing code reuse

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

What is polymorphism?

A

Ability of different classes (with same parent) to change the behaviour of the same method.
ex:
Parent class: Animal
Child classes: Dog, Cat
method in Animal, sound( ), changes bases on animal

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

TF: A static method can use a non-static member

A

False. Static methods belong to class itself while non-static member belongs to instance of that class

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

TF: Strongly typed languages means variables must be declared with a specific type and type conversions are explicit

A

True

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

What is Singleton pattern?

A

Design pattern where only one instantiation of a class is allowed

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

What are the three methods of implementing a Singleton pattern?

A
  1. Eager Initialization method
  2. Lazy Initialization method
  3. Thread Safe Signleton method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which Singleton Pattern implementation method initializes the object at the time of class loading?

A

Eager Initialization method

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

What is the advantage of Eager Initialization implementation of Singleton pattern?

A

Very simple to implement

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

What are disadvantages of Eager Initialization implementation of Singleton pattern?

A
  • Object is always instantiated even if it is never used (resource wastage, CPU time wastage)
  • Cannot use Exception Handling
17
Q

Which Singleton Pattern implementation methods initializes the object only when it is requested? (2)

A
  • Lazy Initialization method
  • Thread Safe Singleton method
18
Q

What are the advantages of Lazy Initialization implementation of Singleton pattern?

A
  • Creation takes place only when required
  • Exception handling possible
19
Q

What is a disadvantage of Lazy Initialization implementation of Singleton pattern?

A

There is a need to check null condition each time

20
Q

Which Singleton Pattern implementation method uses synchronization to ensure the safe creation of a singleton instance in a multi-threaded environment?

A

Thread Safe Singleton Method

21
Q

What are the advantages of Thread Safe Singleton implementation of Singleton pattern? (2)

A
  • Lazy initialization possible
  • Thread-safe
22
Q

What is a disadvantage of Thread Safe Singleton implementation of Singleton pattern?

A

getInstance( ) method synchronized which slows performance as it restricts simultaneous access to it by multiple threads