Object Oriented Design Heuristics

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following best describes the primary purpose of using interfaces in object-oriented design?

  • To directly instantiate objects without needing concrete classes.
  • To define the implementation details of a class.
  • To declare the intent or contract that implementing classes must adhere to. (correct)
  • To hide data members from subclasses.

In object-oriented programming, what is the key difference between an abstract class and an interface?

  • An abstract class declares intent, while an interface provides implementation details.
  • An abstract class supports multiple inheritances, while an interface supports only single inheritance.
  • There is no difference; the terms are interchangeable.
  • An abstract class can incorporate implementations for some methods, while an interface only declares method signatures. (correct)

What does 'Encapsulation' achieve in object-oriented design?

  • It makes all functions and data-members public.
  • It allows direct access to data members from anywhere in the program.
  • It bundles data and the methods that operate on that data, controlling access to protect the integrity of the data. (correct)
  • It prevents the modification of methods by subclasses.

What is the most important guideline to follow when using inheritance in object-oriented design?

<p>Only inherit elements that are public or protected to maintain encapsulation and relevance. (C)</p> Signup and view all the answers

What does method overriding allow in the context of inheritance?

<p>Allowing a subclass to provide a specific implementation for a method that is already defined in its superclass. (D)</p> Signup and view all the answers

What is the significant benefit of method overriding in object-oriented design?

<p>It enhances understandability by providing specific implementations that fit the subclass, signaling an 'is-a' relationship and supporting code reuse. (D)</p> Signup and view all the answers

How does good object-oriented design contribute to the robustness and sustainability of a system's architecture?

<p>By making it harder to make bad design decisions that erode the architecture. (D)</p> Signup and view all the answers

Why is it important for classes to be easily understandable in terms of the domain concept they represent?

<p>It promotes maintainability and clarity, ensuring that the code reflects the problem domain directly. (A)</p> Signup and view all the answers

In the context of object-oriented design, what does it mean for a class to have a single responsibility?

<p>The class should focus on one specific area of functionality within the system. (A)</p> Signup and view all the answers

How is modularity conceptualized in terms of coupling and cohesion?

<p>Loose coupling and high cohesion indicate good modularity. (A)</p> Signup and view all the answers

What does the 'Law of Demeter' aim to minimize in software design?

<p>The degree of coupling between objects. (D)</p> Signup and view all the answers

According to the Law of Demeter, under what circumstance can an object O invoke methods of another object?

<p>Object O can only invoke methods of itself, its parameters, objects it creates, or its direct component objects. (B)</p> Signup and view all the answers

What does the Single Responsibility Principle (SRP) advocate for in object-oriented design?

<p>Each class should have one and only one reason to change. (A)</p> Signup and view all the answers

What does the Open/Closed Principle state?

<p>Classes should be open for extension but closed for modification. (C)</p> Signup and view all the answers

What does the Dependency Inversion Principle (DIP) recommend?

<p>Depend upon abstractions, not concretions. (B)</p> Signup and view all the answers

Flashcards

Interfaces

Declare intent, define functions implemented by classes.

Abstract Classes

Declare intent and incorporate implementations, useful as extension points

Encapsulation

Public, protected or private functions and data members

Inheritance

A class inherits functions and data-members from another class.

Signup and view all the flashcards

Overriding

A sub-class re-defines a method declared in superclass.

Signup and view all the flashcards

Good Design

Architectures erode as a result of bad design decisions.

Signup and view all the flashcards

Separation of Concerns

Code areas of responsibility should be straightforward to identify

Signup and view all the flashcards

Module

Design construct in terms of which we understand the system

Signup and view all the flashcards

Coupling

Degree of interaction across module boundaries.

Signup and view all the flashcards

Cohesion

Degree of interaction within modules.

Signup and view all the flashcards

Law of Demeter

Encourages loose coupling and high cohesion.

Signup and view all the flashcards

Single Responsibility

Classes should have just a single responsibility

Signup and view all the flashcards

Open-Closed Principle

Objects should be open for extension, but closed for modification.

Signup and view all the flashcards

Liskov Substitution

Objects should be replaceable with instances of their sub-types without affecting program correctness.

Signup and view all the flashcards

Interface Segregation

Many client-specific interfaces are better than one general-purpose interface.

Signup and view all the flashcards

Study Notes

  • Object Oriented Design Heuristics is a concept within Software Reengineering.

Interfaces and Abstract Classes

  • Used to define key components in a system.
  • Interfaces declare intent by defining functions implemented by classes.
  • Abstract classes declare intent and incorporate implementations for some methods.
  • Abstract classes serve as extension points, which is particularly useful in software frameworks.
  • With Encapsulation/Information hiding, function and data members can be public, protected, or private.

Inheritance

  • Allows a class to inherit functions and data members from another class.
  • Elements inherited should only be public or protected.
  • Inheritance is key to using abstract classes.
  • Overriding occurs when a sub-class re-defines a method declared in a superclass.
  • Overriding supports understandability as it signals an "is-a" relationship between components.
  • Inheritance supports code reuse.

Good Design

  • Architectures erode due to bad design decisions, often made when the system is unclear.
  • Good design ensures system architecture is easy to understand via:
    • Judicious use of design constructs.
    • Decomposing the system into clear and obvious modules.
  • Good design makes architectures more robust and sustainable by making it harder to make bad decisions.

Relating Domain Concepts to Code

  • Related data and behavior should reside in the same place.
  • Classes should be entirely understandable via domain concepts and self-contained by not relying on other classes.
  • Classes should have a single responsibility and should not be too large.
  • "Separation of Concerns" means that code areas of responsibility should be straightforward to identify.

Modularity

  • A module serves as a design construct that facilitates system understanding, typically classes in an OO system.
  • Software should be understandable in terms of modules without excessive dependence.
  • Modules should be easily replaceable, reusable, extendable, and adaptable.
  • Modularity can be conceptualized by:
    • Coupling: Degree of interaction across module boundaries.
    • Cohesion: Degree of interaction within modules.

Law of Demeter

  • Design heuristic encouraging loose coupling and high cohesion.
  • Also known as “Don't talk to strangers”.
  • Method M in Object O may only invoke methods in the following objects:
    • O itself.
    • M's parameters.
    • Any objects created/instantiated within M.
    • O's direct component objects.
  • Avoid calling methods on objects returned by another method and "lots of dots" call-chains, such as x.y().z()...

SOLID Object Oriented Design Principles

  • Single Responsibility Principle (SRP): Classes and methods should have a single responsibility.
  • Open-Closed Principle: Objects should be open for extension, but closed for modification without sourcing the code.
  • Liskov Substitution Principle: Objects should be replaceable with instances of their subtypes without affecting program correctness.
  • Interface Segregation Principle: Many client-specific interfaces are better than a general-purpose interface; code should not depend on interfaces with unused methods.
  • Dependency Inversion Principle: Code should depend upon abstractions, not concretions.

Summary

  • High Level Heuristics includes a clear relationship between problem domain and software modules and modular design that has loose coupling and high cohesion.
  • Interfaces and abstract classes convey design intent and highlight key components.
  • Visibility of data and functions can be controlled to reduce complexity and avoid misuse.
  • Inheritance enables code-reuse and extensibility while signaling domain relationships between classes.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser