Object Oriented Flashcards

1
Q

What is Object-oriented (OOP)

A

Object-oriented programming is based on objects, self contained entities containing data and logic.

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

What are the Four Fundamentals of OOP

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

Describe Encapsulation

A

Encapsulation
Encapsulation is the concept of wrapping variables and methods (data and code/functionality) together into a single unit.
Provides control over the data and manipulation of the data/defines functionality coupled with the data.
Pros: Access control, readability, separation of concerns, easy to test.
Cons: Overhead in code length and instructions (Documentation)\
Examples:
Profile object contains various methods for accessing audiences/behaviors/contribution information/ids etc. Controls mutability, must rely on methods to access read data, but other classes (Builder/Transformer) to apply changes.

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

Describe Inheritance

A

The ability for a class to gain access to properties/functionality (variables/methods) of another class.
The class that inherits is the child/sub
The class that grants is the parent/super
Keywords:
extend - keyword for inheriting
super - accessing the parent class/variables (Similar to this)
implements - access properties of an interface
NEW: Java now supports multiple inheritance through extension (Previously it was limited to only interfaces)
Pros: Reusability and improves encapsulation
Cons: Dependence of subclass in parent classes (Can be harder to change underlying functionality)
Examples:
Reaction Pipeline, has a base pipeline interface to support functions for accepting/processing/passing data. Abstract instances allow for further generic definition of logging/metrics gathering, concrete instances support specific processing logic.

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

Describe Abstraction

A

The separation of intent (process) and functionality. Allows code to specify what is being done instead of how (And leaving the how up to specific implementations)
Keyword abstract (class level keyword that allows for inclusion of abstract methods)
Pros - Avoids duplication, increases reusability. Reduces usage complexity (Via hiding implementation and/or defining patterns)
Cons - Can make it more difficult to understand, limits flexibility.
Examples:
We have many partner integrations that send data to some location. We can abstract out the actual send logic, so we have access to the intent, but it’s up to the concrete instances to supply how that happens.

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

Describe Polymorphism

A

The ability for one object to act as another. The most common being a parent class reference used for a child class. Any object that can pass a IS-A test is considered to be polymorphic.
Pros: Re-usability
Cons: Difficult to follow, double edged-sword if not used correctly, can lead to difficult to follow code.
Examples:
Reactor Pipeline, allows us to configure a chain of pipelined objects without having to know the exact concrete class and ordering (Polymorphism allows us to reference the parent class when using concrete instances)
DAO Layer, the resource layer references the interface/parent, and allows us to swap in any implementation (MySql, Aurora, Mongo … etc)

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

Class vs Object

A

Class - A class is like a blueprint or template from which objects are created.
A logical entity
Classes can define single instance logic/variables through use of the static keyword
Object - An object is a specific instance of a class.
A physical entity
Objects can use the keyword this to refer to their own variables/methods

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

What are the pros and cons of OOP

A

Pros:
Code reusability (Easier to implement/less maintenance cost)
Reduces redundant code by using inheritance.
Data abstraction can help with security.
Easier to maintain/improve due to extensibility, especially as applications grow in feature requirements.
Cons
Complexity - Usually there is allot more boilerplate to OOP.
Slow - Sometimes using Object-oriented Programming approach can take a heavier toll on memory/processing speeds.

Good to use for Large/complex applications, modeled off of the real world

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

Descrive Inversion of Control (AKA Dependency Injection for Java)

A

An object or function receives other objects or functions as opposed to creating them internally. Separation of the constructing of an object from the usage of them, which helps to loosely couple the components. It makes implicit dependencies explicit.

Dependency injection is often used alongside specialized frameworks called “Containers”.
Note: Most of the programming I have done thus far does not use Containers, but Composers. Composers are simpler and construct services/clients and inject things manually. A Container is more like Spring, where you do not specify things explicitly but it is done inheritance

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

Describe Composition over Inheritance

A

In general polymorphic behavior was attained via inheritance and/or overriding. This concept is that it should be achieved by containing instances of other classes that implement the desired functionality.

The concept is to break down the functionality/behaviors of a class, and provide that functionality via an interface and concrete classes (Usually supplied to the class via dependency injection)

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