CHAPTER 9 - Code Reuse, Making Changes in Class Hierarchy

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

13 Terms

1
New cards

Code reuse

is the practice of using existing code to develop new applications.

2
New cards

Code reuse

It is a fundamental principle of software engineering that allows developers to save time and effort by leveraging existing code libraries, frameworks, and modules.

3
New cards

Inheritance, Composition, Delegation

3 ways to achieve code reuse

4
New cards

Inheritance

is a mechanism that allows a class to inherit properties and methods from another class. In this approach, a subclass (or derived class) is created by inheriting properties and methods from a superclass (or base class). This enables the subclass to reuse the code from the superclass without having to rewrite it. It is useful when creating a family of related classes that share common functionality

5
New cards

Composition

is a mechanism that allows a class to contain instances of other classes as members. In this approach, a class is composed of one or more objects of other classes. This enables the class to reuse the functionality of the contained objects without inheriting from them. It is useful when creating complex classes that have a set of common behaviors, but the relationships between the behaviors are not well-defined.

6
New cards

Delegation

is a mechanism that allows a class to delegate responsibility for a task to another class. In this approach, a class delegates the implementation of a method to another object that is responsible for providing the implementation. This enables the class to reuse the functionality of the delegate object without having to implement it itself. It is useful when creating classes that have a single responsibility and collaborate with other classes to achieve that responsibility

7
New cards

Is-a

In Java, an "__-_" relationship is a term used to describe the relationship between two classes, where one class is a specialized version of the other. This relationship is also known as Inheritance or subclassing. In this relationship, the subclass (or derived class) inherits properties and behaviors from its superclass (or base class)

8
New cards

Is-a

The "__-_" relationship is important in Java because it allows developers to reuse code and create more efficient and flexible programs. By using inheritance, developers can create a hierarchy of classes that share common properties and behaviors, while also allowing for specialization and customization in subclasses. This can help to reduce code duplication, improve code readability and maintainability, and make it easier to add new features and functionality to a program over time

9
New cards

Has-A-Relation

In Java, ___-_-________ is a type of relationship between classes, which is used to define the ownership of one object by another object. This relationship is also known as composition or aggregation.

10
New cards

Has-A-Relation

Composition is a strong form of the ___-_-________, where one class owns the other class and is responsible for its lifetime. If the owner class is destroyed, then the owned class is also destroyed.

11
New cards

Containment, whole-part

Composition represents "___________" a "_____-____" or relationship between two classes, where one class is composed of one or more objects of another class.

12
New cards

Aggregation

___________ in Java is a type of relationship between two classes where one class, the aggregate class, has a reference to the other class, the part class. The aggregate class is considered to own the part class

13
New cards

Delegation

__________ is a mechanism that allows a class to delegate responsibility for a task to another class. In this approach, a class delegates the implementation of a method to another object that is responsible for providing the implementation. This enables the class to reuse the functionality of the delegate object without having to implement it itself. It is useful when creating classes that have a single responsibility and collaborate with other classes to achieve that responsibility.