Object-Oriented Design Concepts

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 core idea behind designing with independent components in object-oriented design?

  • Ensuring that all components are tightly coupled to guarantee system-wide consistency.
  • Creating mini-programs that perform specific tasks and can be combined to build larger systems. (correct)
  • Maximizing the use of global variables to enhance data sharing between components.
  • Focusing on creating monolithic programs to reduce the complexity of deployment.

What is the primary purpose of encapsulation in object-oriented programming?

  • To allow direct access to an object's data from anywhere in the program.
  • To enable the creation of global functions that can operate on any object.
  • To increase the complexity of interactions between different parts of the system.
  • To bundle data and methods that operate on that data into a single unit, and restrict direct access to some of the object's components. (correct)

What is the main benefit of information hiding in object-oriented design?

  • It increases the number of dependencies between objects, making the system more robust.
  • It encourages the use of global variables to share state across different objects.
  • It limits interactions between components, protecting object integrity by hiding internal details and reducing combinatorial explosion. (correct)
  • It makes all internal details of an object publicly accessible for easier debugging.

In object-oriented programming, what does inheritance enable?

<p>A class (child) to acquire the properties and behavior of another class (parent), promoting code reuse and hierarchy creation. (D)</p> Signup and view all the answers

What is the primary focus of polymorphism in object-oriented programming?

<p>To allow objects of different types to be treated as objects of a common type, enabling methods to be implemented differently depending on the object type. (D)</p> Signup and view all the answers

What is the main goal of abstraction in software design?

<p>To hide complex implementation details and only expose essential functionalities to the user. (A)</p> Signup and view all the answers

Which principle is most directly violated when a class has multiple reasons to change?

<p>Single Responsibility Principle (D)</p> Signup and view all the answers

What is the primary goal of the Open/Closed Principle?

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

Which of the following best describes the Liskov Substitution Principle (LSP)?

<p>Derived classes must be substitutable for their base classes without altering program correctness. (D)</p> Signup and view all the answers

What is a 'code smell'?

<p>An indicator of potential problems in code that may require refactoring. (D)</p> Signup and view all the answers

Which code smell involves duplicating the same code in multiple locations?

<p>Duplicate Behavior (B)</p> Signup and view all the answers

What is the 'Don't Repeat Yourself' (DRY) principle primarily aimed at preventing?

<p>Duplication of code, logic, or data in a system. (D)</p> Signup and view all the answers

What does the 'Primitive Obsession' code smell indicate?

<p>Sticking with built-in types instead of making classes. (D)</p> Signup and view all the answers

What design principle is most directly violated by the 'Feature Envy' code smell?

<p>Information Expert (D)</p> Signup and view all the answers

What is the primary solution recommended for addressing 'Conditional Complexity'?

<p>Using polymorphism to handle different cases. (B)</p> Signup and view all the answers

What does 'Shotgun Surgery' generally indicate about code?

<p>A single change requires modifications to multiple classes. (B)</p> Signup and view all the answers

What is the recommended solution for the 'Lazy Class' code smell?

<p>Inline its behavior into other classes. (B)</p> Signup and view all the answers

Which of the following best describes the 'Data Class' or 'Anemic Domain Model' code smell?

<p>A class that only contains data and not behavior. (A)</p> Signup and view all the answers

What does the YAGNI principle suggest?

<p>You aren't gonna need it. Don't add functionality until deemed necessary. (B)</p> Signup and view all the answers

What does DTSTTCPW stand for?

<p>Do The Simplest Thing That Could Possibly Work (D)</p> Signup and view all the answers

Flashcards

Encapsulation

Bundles data and methods into a single unit, restricting direct access and providing controlled interaction.

Information Hiding

Hiding internal details to limit interactions between components and protect object integrity.

Object-Oriented Programming

A programming paradigm where software is structured around objects that combine data and behavior.

Inheritance

Allows a class to acquire properties and behavior from another class, promoting code reuse.

Signup and view all the flashcards

Polymorphism

Allows methods to be implemented differently depending on the object type.

Signup and view all the flashcards

Abstraction

Hides complex implementation details and only exposes essential functionalities.

Signup and view all the flashcards

Composition

Building objects by combining simpler ones, creating a 'has-a' relationship.

Signup and view all the flashcards

Delegation

Assigns tasks to objects that are designed to handle them directly

Signup and view all the flashcards

Information Expert

Assigns responsibility to the class that has the information needed to fulfill it

Signup and view all the flashcards

Separation of Concerns

Divides a program into distinct sections, each addressing a separate concern, enhancing modularity and maintainability

Signup and view all the flashcards

Open/Closed Principle

Software entities should be open for extension but closed for modification.

Signup and view all the flashcards

Liskov Substitution Principle

Derived classes must be substitutable for their base classes without altering program correctness.

Signup and view all the flashcards

Duplicate Behavior

Code that works but is duplicated, making maintenance difficult.

Signup and view all the flashcards

Long Methods & Large Classes

Large classes or methods are hard to understand, maintain and reuse.

Signup and view all the flashcards

Primitive Obsession

Sticking with built-in types instead of creating custom classes, often results in long parameter lists.

Signup and view all the flashcards

Divergent Change

Same class is changed for different functions and this violates separation of concerns

Signup and view all the flashcards

Feature Envy

Move the method to class where most/all of the data used is found.

Signup and view all the flashcards

Anemic Domain Model

Data Class or Anemic Domain Model is a class that only contains data and not behavior.

Signup and view all the flashcards

Null Object

Provides a non-functional object instead of using null.

Signup and view all the flashcards

Structural Patterns

Simplifies the structure of complex systems through flexible class and object composition.

Signup and view all the flashcards

Study Notes

  • These notes cover key concepts in object-oriented design and common code smells, along with design patterns and related terms.

Object-Oriented Design (OOD)

  • A software design approach structuring code around "objects" with data (attributes) and behavior (methods).
  • OOD mirrors real-world entities, promoting modularity, reusability, and maintainability.

Independent Components

  • Used to avoid combinatorial explosion, as each element can exponentially grow software complexity.
  • Objects are mini-programs with their data and operations (similar to Unix utilities combined for larger tasks).
  • Object-oriented programming involves making small, simple, specialized programs and combining them.

Encapsulation

  • Bundles data and methods into a single unit, restricting direct access and controlling interaction.
  • Information hiding limits interactions between components, preventing combinatorial explosion and protecting object integrity.
  • An object exposes only necessary information at the appropriate level.

Inheritance

  • Enables a class (child) to inherit properties and behavior from another class (parent) for code reuse and hierarchy.
  • Allows extending or overriding parent functionality.

Polymorphism

  • Allows methods to be implemented differently based on the object type.
  • Supports overriding in derived classes and providing a unified interface.

Composition

  • Builds objects by combining simpler ones in a "has-a" relationship.

Delegation

  • Assigns tasks to helper objects directly, promoting modularity and avoiding deep inheritance.

Abstraction

  • Hides complex implementation details, exposing only essential functionalities.

Information Expert

  • Assigns responsibility to the class with the information needed to fulfill a task.

Separation of Concerns

  • Divides a program into distinct sections, each addressing a separate concern to enhance modularity and reduce complexity.

Package Coupling Principles

  • Aims to minimize dependencies between packages, promoting independent development and reducing ripple effects from changes.

Package Cohesion Principles

  • Organizes related classes and components into logical groupings for clarity and consistency.
  • Facilitates easier maintenance and scalability.

Favor Composition Over Inheritance

  • Promotes the use of composition ("has-a" relationship) over inheritance ("is-a") for flexibility and reduced dependency.

Single Responsibility Principle (SRP)

  • A class should have only one reason to change, ensuring a focused purpose.
  • SRP simplifies debugging, maintenance, and reduces code duplication.

Liskov Substitution Principle (LSP)

  • Derived classes must be substitutable for base classes without altering program correctness.
  • LSP ensures derived classes maintain the behavior of base classes and promotes robust, extensible designs.
  • Violating the LSP results in brittle systems with unexpected side effects from new derived classes.

Open/Closed Principle

  • Software entities should be open for extension but closed for modification for scalability.
  • Reduces the risk of introducing bugs.

Code Smells

  • Indicators of potential problems in code.

Duplicate Behavior

  • Involves duplicated code blocks, leading to maintenance issues, potential bugs, and difficulty adapting to change.
  • Solve by applying the Don't Repeat Yourself (DRY) principle, using methods, composition, or inheritance to unify similar pieces of logic.

Large Methods & Large Classes

  • Indicated by excessive code length, scrolling, or numerous fields.
  • Make the code hard to understand, maintain, and reuse while violating OOP principles.

Primitive Obsession

  • Refers to over-reliance on built-in data types instead of creating classes.

Data Clump

  • Data that is often found together.

Long Parameter Lists

  • Make code harder to maintain and can indicate the method is in the wrong class.
  • Use Cohesion (encapsulate a data clump into a meaningful class).

Divergent Change

  • Occurs when a class is modified for different, unrelated reasons.
  • Solution: Break up the class so it only does one concern.

Shotgun Surgery

  • Occurs when a single change requires modifications in multiple classes.

Feature Envy

  • A method accesses data from another class more than its own.
  • Move the method to the class where the data it uses resides.

Conditional Complexity

  • Refers to large and growing if-else and switch statements.
  • Solution: Use Polymorphism.

Parallel Inheritance Hierarchies

  • Every time class is added to one package, a class gets added to another package

Lazy Class

  • A code class that has very little functionality

Middle Man

  • When a class delegates the majority of work functionality elsewhere

Data Class or Anemic Domain Model

  • A class that only contains state and no behavior

Alternative Classes with Different Interfaces

  • Classes that do not share the same supertype

Speculative Generality

  • Code written to handle future cases or eventualities

God Class/Method

  • A class or method that is too large and attempts to perform too many functions

Temporary Field

  • Class or instance fields that are temporarily set for method operations

Message Chains or Train Wrecks

  • Reaching into an object's attributes to call the attribute's methods.

Refactoring

  • Involves improving code without adding new functionality.
  • Dirty code is a result of shortcuts

Design Patterns

  • Typical solutions to common problems in software design.
  • Design patterns are a toolkit of tried and tested solutions to common problems in software design.

Creational Patterns

  • Deal with object creation mechanisms

Structural Patterns

  • Focus on class and object composition

Behavioral Patterns

  • Handle object interaction and responsibilities

Creational Patterns

  • Abstracts the instantiation process, decoupling object creation from client code

Structural Patterns

  • Simplifying the structure of complex systems through flexible class and object composition

Behavioral Patterns

  • Concerned with object interaction, communication, and responsibility delegation

Utility Class/Helper Class

  • Groups together related static methods that perform common tasks

Template View (SSR)

  • Uses server-side templates to render HTML pages.

Transform View (CSR)

  • Renders content on the client side, often using JavaScript frameworks.

Key Design Patterns

  • Provide standardized solutions to design issues
  • Enhance code readability, maintainability, and flexibility

Creational Patterns

  • Factory Method
  • Abstract Factory
  • Builder
  • Prototype
  • Singleton

Structural

  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy

Behavioral

  • Chain of Responsibility
  • Command
  • Iterator
  • Mediator
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

Studying That Suits You

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

Quiz Team

Related Documents

More Like This

객체지향 프로그래밍의 캡슐화
6 questions
Object-Oriented Design and SOLID Principles
25 questions
Object Oriented Design Heuristics
15 questions
Use Quizgecko on...
Browser
Browser