1/12
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Code reuse
is the practice of using existing code to develop new applications.
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.
Inheritance, Composition, Delegation
3 ways to achieve code reuse
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
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.
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
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)
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
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.
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.
Containment, whole-part
Composition represents "___________" a "_____-____" or relationship between two classes, where one class is composed of one or more objects of another class.
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
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.