Coupling vs Cohesion Quiz

LargeCapacityPreRaphaelites avatar
LargeCapacityPreRaphaelites
·
·
Download

Start Quiz

Study Flashcards

12 Questions

What does the Dependency Inversion Principle (DIP) suggest?

Rely on abstract interfaces rather than concrete components

Why is it considered a violation of the Interface Segregation Principle (ISP) when Mustang must implement new operators meant for DeLorean?

It contradicts the idea of using client-specific interfaces

How do the SOLID principles contribute to software design?

They lead to robust, easy-to-maintain, and extendable software

What is a key characteristic of traditional components in Component Based Software Engineering?

Emphasis on functions and data structures rather than encapsulation

Why should a Square be defined as a separate Shape rather than extending the Rectangle class?

To maintain low coupling and high cohesion in software design

In the context of Interface Segregation Principle (ISP), why is it recommended to have client-specific interfaces?

To prevent unnecessary dependencies from arising between classes

What does cohesion measure?

How closely the responsibilities of a module are related to each other

Which principle states that a component should be open for extension but closed for modification?

OCP (Open Closed Principle)

What is the main problem with high coupling?

Modules are strongly interconnected

Which principle states that subclasses should be substitutable for their base classes?

LSP (Liskov Substitution Principle)

In the context provided, what would be the best solution for managing multiple shapes without violating the Open Closed Principle?

Create a new Abstract class called Shape with an abstract operator draw() and override it for each 'new' shape

What is the main benefit of having low coupling between modules?

Modules are relatively independent, making the system more flexible and easier to maintain

Study Notes

SOLID Principles

  • Introduced in the early 2000s to achieve low coupling and high cohesion in software
  • Makes software easy to maintain, extend, and robust

Dependency Inversion Principle (DIP)

  • Do not depend on concrete components, instead depend on abstractions
  • A component should not depend on other concrete components
  • Violation: DeliveryCompany creating an instance of DeliveryDriver, making it dependent on a lower level concept

Interface Segregation Principle (ISP)

  • Many client-specific interfaces are better than one general purpose interface
  • Create a specialized interface to serve each major category of clients
  • Violation: Adding new operators to a Car Interface, forcing Mustang to implement unnecessary operators

Component-Based Software Engineering

  • Focuses on functions and data structures
  • Design of processing logic governed by algorithm design and structured programming
  • Design of data structures defined by the data model
  • Design of interfaces governed by collaborations that a component must effect

Coupling vs Cohesion

  • Cohesion: how closely a module's responsibilities are related
  • Coupling: how much one module relies on another
  • High cohesion and low coupling make a system more flexible and easier to maintain

Open-Closed Principle (OCP)

  • A component should be open for extension but closed for modification
  • Achieved by creating abstractions that serve as a buffer between functionality and design class
  • Violation: Changing existing code in ShapePrinter class to manage a new shape
  • Solution: Create an abstract class called Shape with an abstract operator that can be overridden for each new shape

Liskov Substitution Principle (LSP)

  • Subclasses should be substitutable for their base classes
  • A component using a base class should continue to function properly if a derived class is passed instead
  • Violation: Creating a Square class that extends a Rectangle class, assuming a Square is a subclass of a Rectangle

Test your knowledge on the concepts of coupling and cohesion in software engineering. Understand the difference between high and low cohesion, as well as high and low coupling, and their implications on software design and maintainability.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser