Object-Oriented Design Principles Chapter 10

InexpensiveHope avatar
InexpensiveHope
·
·
Download

Start Quiz

Study Flashcards

40 Questions

What is the primary purpose of a design in object-oriented design principles?

To describe how something will work in a context using requirements

What principle is related to the idea of loose coupling?

The Principle of Least Knowledge (PLK)

What is the purpose of the Liskov Substitution Principle (LSP)?

To ensure subtypes are substitutable for their base types

What is the goal of the Dependency Inversion Principle (DIP)?

To depend on abstractions rather than concrete classes

What is the focus of the Interface Segregation Principle (ISP)?

To prevent clients from depending on interfaces they don't use

What is an example of a design style in object-oriented design principles?

Styles of Design

What is the other name for the Principle of Least Knowledge (PLK)?

The Law of Demeter

What is the purpose of an interface in object-oriented design principles?

To provide a common set of methods for related classes

What is the main cause of LSP violations in derived classes?

Method overriding

What is the purpose of abstracting out common things in the DRY principle?

To avoid duplicate code

What is the consequence of a sub-class throwing exceptions to hide certain behavior defined in its super class?

It violates the LSP

What is the primary responsibility of a class according to the Single Responsibility Principle?

To have a single responsibility

What is the purpose of the Don't Repeat Yourself principle?

To avoid code duplication

What is an example of LSP violation in a sub-class?

Overriding a virtual method with an empty implementation

What is the name of the principle that advises against duplicate code?

Don't Repeat Yourself

What is the consequence of a class having multiple responsibilities?

It violates the Single Responsibility Principle

What is the main idea behind the Dependency Inversion Principle?

Higher-level modules should depend on abstractions.

What is the primary purpose of the design principles in object-oriented design?

To provide guidelines for creating a good design that is easy to implement and maintain

What is a potential issue with deep inheritance trees?

They can lead to tight coupling.

What is the purpose of abstraction in object-oriented design?

To provide a common interface for different implementations.

What is the outcome of encapsulating things in your design that are likely to change?

Classes are protected from unnecessary changes

What is the effect of exposing member data in public?

It compromises data integrity.

What is an example of a class that remains relatively constant throughout the program?

Violinist class

What is the benefit of coding to an interface rather than to an implementation?

It increases the flexibility of the design

What is the purpose of interfaces in object-oriented design?

To provide a common interface for different implementations.

What is the significance of the open triangle in a UML diagram?

It represents inheritance.

What is the purpose of the Open-Closed Principle (OCP)?

To make classes open for extension and closed for modification

What is the problem with data-only classes?

They lack behavioral functionality.

What is an example of a class that implements the Shape interface?

Rectangle class

What is the purpose of the Liskov Substitution Principle?

To ensure that subclasses can be used as their base classes.

What is the benefit of separating the features and methods of a class that remain relatively constant throughout the program from those that will change?

It makes the design more flexible and easier to maintain

What is an example of a feature that will change in the Violinist class?

play() method

When a class is used as part of another class but still exists outside of that class, what is this concept called?

Aggregation

What is the main idea behind the Principle of Least Knowledge?

Talk only to your immediate friends

What is the complement to strong cohesion in an application?

Loose coupling

What is the purpose of Delegation in object-oriented design principles?

To give responsibility for the behavior to another class

What is the name of the principle that says 'high-level modules should not depend on low-level modules, but both should depend on abstractions'?

Dependency Inversion Principle

What is the concept called when classes are related to each other?

Association

What is the purpose of using Composition in object-oriented design principles?

To have your program use a set of behaviors

Who introduced the 23 class design guidelines?

Davis and McConnell

Study Notes

Object-Oriented Design Principles

  • Designs have a purpose: describe how something will work in a context, using the requirements (lists of features, user stories, and use cases) to define the context.
  • Designs must have enough information: enough details in the design so that someone can come after you and implement the program correctly.

Fundamental Object-Oriented Design Principles

  • Encapsulate things in your design that are likely to change: separate the features and methods of a class that remain relatively constant throughout the program from those that will change.
  • Code to an interface rather than to an implementation: subtypes must be substitutable for their base types.
  • The Open-Closed Principle (OCP): classes should be open for extension and closed for modification.
  • The Don't Repeat Yourself (DRY) Principle: abstract out things that are common and place them in a single location to avoid duplicate code.

Other Design Principles

  • The Liskov Substitution Principle (LSP): subtypes must be substitutable for their base types.
  • The Dependency Inversion Principle (DIP): don't depend on concrete classes; depend on abstractions.
  • The Interface Segregation Principle (ISP): clients shouldn't have to depend on interfaces they don't use.
  • The Principle of Least Knowledge (PLK): talk only to your immediate friends.

Styles of Design

  • Delegation: give responsibility for the behavior to another class.
  • Composition: assemble behaviors from other classes.
  • Association: classes are related to each other.

Class Design Guidelines

  • 1. Don't expose member data in public.
  • 2. Watch for coupling that's too tight (PLK).
  • 3. Avoid deep inheritance trees (LSP).
  • 4. Eliminate data-only classes.
  • 5. Eliminate operation-only classes.
  • 6. Avoid putting methods into the public interface.
  • 7. Be sure to inherit only what you want to inherit (LSP).
  • 8. Present a consistent level of abstraction in the class interface.

Understand the principles of object-oriented design, including the Liskov Substitution Principle and the Dependency Inversion Principle. Learn how to write code that is flexible and maintainable.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser