OOP Midterm Flashcards

1
Q

Uses-a types (3)

A

Dependency

Association

Direct Association

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

Has-a types (2)

A

Aggregation

Composition

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

Is-a types (1)

A

Inheritance

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

Implements-a types (1)

A

Interface Implementation (realization)

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

Dependency

A

transient relationship between two classes. Implementation of class A that uses class B does not affect class A definition

Class B is unaware of the existence of the class A (Asymmetry)

(Minimize this relationship to reduce coupling)

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

Association

A

relationship between Class A and Class B last as long as both object live at runtime. One class is owned by the object of another class

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

dependency example

A

A method of class Sequence uses a Stack class to verify palindrome. A student enrollment class uses a student class in its method

i.e. A method of class A is passed as parameter of class B and returns a value of class B.

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

association example

A

A teacher class has a method to assign students to a class while students can (or can not) specify which teacher is teaching their class

i.e. class A has an attribute that is class B

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

cardinality

A

Defines multiplicity between objects (one-to-one, one-to-many…)

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

direct association

A

A strong connection between classes where both classes are generally aware of each other and have direct references or attributes that link them

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

direct association example

A

A teacher class where each student is defined a specific teacher and each teacher has a direct reference to their student. Both classes are aware of each other

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

association subtypes

A

aggregation

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

composition

A

A child class that cannot exist independently of its parent class

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

composition example

A

Class car has a class Engine. Since Car owns Engine, it controls the lifetime of this class meaning once Car is destroyed, so is Engine

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

aggregation

A

Child class is independent of its parent class meaning its a standalone and unidirectional class that can exist independent of it’s parent class. Association is unidirectional.

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

aggregation example

A

Class University aggregates Class department objects. The department objects can exist independently of the university

i.e. Class A contain objects of class B over period of time. Both objects survive individually

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

restricted form of aggregation

A

composition

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

composition

A

Class A composes or owns class B and represents “part-of” relationship. Class B cannot have an existence without Class A (High dependency)

19
Q

Inheritance

A

Class B is derived and dependent on Class A. Class B can access and utilize members of Class A and extend or specialize behavior of Class A

20
Q

Interface Implementation

A

Class B is a realization of interface A. Class B must override all Class A methods

21
Q

Expansion

A

Mechanism for building on top of existing classes. Building upon capabilities of class A in class B

21
Q

Contraction

A

Specializing and narrowing down the capabilities of a class. Class B restricts or refines behaviors or attributes of inherited Class A

21
Q

transative

A

A property of relationship that extends from one element to another through a series of elements.

i.e. Class A is related to Class B and Class B is related to Class C so Class A is related to Class C

21
Q

concept reuse in inheritance

A

Class B can override behavior of parent class. Class B shares definitions of methods but not implementations

21
code reuse in inheritance
Class B inherits behavior from Class A
22
Contractual Obligation
Overridden method sis required to keep the same name, return type, and parameters as the base class
22
override
Method replacement keyword that tells compiler to replace a method from inherited base class with its derived class's implementation
23
abstract class
a restricted class that acts similar to an interface and can have both abstract and regular methods
24
abstract method
Can only be used in an abstract class and it does not have implementation
25
Forms of Inheritance (8)
Specialization Specification Construction Generalization Extension Limitation Variance Combination
26
Specialization
Child class is a special case of parent class
27
Specification
The parent class defines behavior that is implemented in the child class but not in the parent class. Parent class can be an abstract class or interface and child class is a realization of the parent
28
Construction
Child class makes use of parent's behavior but is not a subtype of the parent (breaks principle of substitution)
29
Principle of Substitution
subclass is a subtype of the parent meaning the object type associated with a value held by a variable may not exactly match the type associated with the declaration for that variable Shape s = Triangle t;
30
Generalization
Child class modifies or overrides some methods of its parent class (opposite of subclassing for specialization) must override one method from parent
31
Extension
Child class adds new functionality to the parent class but does not change inherited behavior no modifications to parent methods, new methods are owned by the child class
32
Variance
The child class and parent class are variants of each other, and the the class-subclass relationship is arbitrary Two or more classes have similar implementations but do no posses any hierarchical relationship between the concepts represented by the classes
33
Multiple (Combination)
The child class inherits features from more than one parent class. i.e. inherits from parent class and implements multiple interfaces
34
benefits of inheritance
software reuse consistency of interface rapid prototyping polymorphism information hiding
35
polymorphism
permits programmer to generate high-level reusable components that can be tailored to fit different applications by changes in their low-level parts
36
Inheritance Disadvantages
Execution Speed Program size Message Passing Overhead Program Complexity
37
Execution Speed
Inherited methods deal with arbitrary subclasses are often slower than specialized code
38
Limitation
The child class restricts the use of inherited parent class behavior