Java Questions regarding Cohesion
- What are the benefits of cohesion?
Answer:
Benefits of Cohesion. The more focused a class is, the higher its cohesiveness.
The key benefit to high cohesion is that such classes are typically much easier to maintain.
Benefits of Cohesion in Software Development
Cohesion refers to the degree to which the various parts of a module or system work together to achieve a single, well-defined purpose. In software development, achieving high cohesion can have a number of benefits, including:
Improved maintainability: Modules with high cohesion are easier to understand and modify, because all the elements within them are related to a single, well-defined purpose. This makes it easier to make changes to the module without causing unintended side effects.
- Enhanced reusability: Modules with high cohesion can be more easily reused in other contexts, because they are self-contained and focused on a specific purpose.
- Improved reliability: Modules with high cohesion are less likely to contain defects, because they are less complex and have fewer parts that could potentially fail.
- Enhanced extensibility: Modules with high cohesion can be more easily extended to support new features or functionality, because they are modular and focused on a specific purpose.
- Overall, achieving high cohesion in software development can help make your code more maintainable, reliable, and reusable, which can save time and resources in the long run.
- What is meant by cohesive design?
Answer: Instead of one class that does everything, we break the system into subclasses.
- What does cohesion mean in computer programming?
Answer:
In computer programming, cohesion refers to the degree to which the elements of a module belong together. Cohesion is a measure of how strongly related each piece of functionality expressed by the source code of a software module is.
Each subclass has a very specific or cohesive role.
- How is the "has-a" concept implemented?
Answer:
"has-a" is implemented by using instance variables that refer to other objects.
- What is a covariant return type?
Answer:
As of Java 5 overriding methods can return a subtype of the declared return type of the superclass.
-
What does aoverloaded method require?
Answer:
An overloaded method requires a change in the argument list.
- What are Overloaded methods allowed to vary?
Answer:
Overloaded methods are free to vary the 1) return type 2) access modifier 3) declared exceptions
- What is the relationship between a class and an interface?
Answer:
1) A class can implement more than one interface 2) An interface can extend another interface
- What is the difference between inheritance and composition?
Answer:
Composition is an object oriented design concept that is closely related to inheritance, as it also deals with reusing classes; but it focuses on establishing HAS-A relationship between classes. So unlike Inheritance, which deals with extending features of a class, composition
reuses a class by composing it. Composition is achieved by storing reference of another class as a member.
- What is the default constructor?
Answer:
The compiler-generated constructor is called the default constructor, and it is always a no-arg constructor with a no-arg call to super().