OOP Flashcards

1
Q

Explain the difference between class and objects

A

Object bundled the attributes and methods that act on the object

Classes is a template used when creating objects, which describes the attributes and methods (interface) that the object will have

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

Define Encapsulation and state its purpose

A

Encapsulation is the bundling of data and the methods that acts on the data into an object

Purpose:
1. This is to prevent inadvertent modification of data
2. The interface is separated from its implementation (information hiding from developers)

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

Advantages of Encapsulation

A

Feature: prevent inadvertent modification
A: lower likelihood of bugs
Reason: Developers less likely to change an attribute which may cause bugs

Feature: interface separate from implementation
A: More efficient development
R: high modularity; the system can be maintained in two different modules
R: high abstraction; developers don’t need to worry about implementation, and can focus more on how the interfaces interact with each other to achieve their aim

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

Define Inheritance and state its purpose

A

Inheritance refers to the child class being able to access parent’s public methods.

Purpose: to encourage code reuse

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

Advantages of inheritance

A

Feature: Able to inherit public methods from parents class
A: Reduce the likelihood of bugs
A: Able to complete his task faster and more efficiently
R:
With inheritance, developer only needs to write implementation once and can inherit via super() method and don’t have to write the implementation again.
Thus this reduces duplicate code and reduces reduces code redundancies.
The developer only have to change the implementation at one location instead of many locations,
thus lowering the likelihood of missing a location.

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

Define polymorphism and state its purpose

A

Polymorphism refers to the ability of different methods with same name to exhibit different behaviours at runtime.

Purpose: Promotes code generalisation

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

Advantage of polymorphism

A

Feature: code generalisation; common interface between objects
A: Enhance efficiency/ Reduces confusion
R:
By having a common interface, developers will not get confused over similar methods name of different objects that carry out the same general function.
A clear and common interface will eliminate the need to remember many similar method names, enabling developers writing the interactions of object to reference the predetermined interface, thus increasing coding efficiency

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

Things to note when drawing class diagrams? (6)

A
  1. Class name has capital first letter and is SINGULAR
  2. PRIVATE attributes (-)
  3. PUBLIC getter and setter methods for all attributes (+) (unless really obvious not to)
  4. Arrow pointing from CHILD class TO PARENT class
  5. Arrow is hollow
  6. Read the context and add additional methods where appropriate
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between Class and object

A

Class is a template which is used to create objects containing the specified methods and attributes .

Objects bundles the attributes and methods that acts on the object together

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