Podcast
Questions and Answers
Which of the following best describes the primary purpose of using interfaces in object-oriented design?
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?
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?
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?
What is the most important guideline to follow when using inheritance in object-oriented design?
What does method overriding allow in the context of inheritance?
What does method overriding allow in the context of inheritance?
What is the significant benefit of method overriding in object-oriented design?
What is the significant benefit of method overriding in object-oriented design?
How does good object-oriented design contribute to the robustness and sustainability of a system's architecture?
How does good object-oriented design contribute to the robustness and sustainability of a system's architecture?
Why is it important for classes to be easily understandable in terms of the domain concept they represent?
Why is it important for classes to be easily understandable in terms of the domain concept they represent?
In the context of object-oriented design, what does it mean for a class to have a single responsibility?
In the context of object-oriented design, what does it mean for a class to have a single responsibility?
How is modularity conceptualized in terms of coupling and cohesion?
How is modularity conceptualized in terms of coupling and cohesion?
What does the 'Law of Demeter' aim to minimize in software design?
What does the 'Law of Demeter' aim to minimize in software design?
According to the Law of Demeter, under what circumstance can an object O invoke methods of another object?
According to the Law of Demeter, under what circumstance can an object O invoke methods of another object?
What does the Single Responsibility Principle (SRP) advocate for in object-oriented design?
What does the Single Responsibility Principle (SRP) advocate for in object-oriented design?
What does the Open/Closed Principle state?
What does the Open/Closed Principle state?
What does the Dependency Inversion Principle (DIP) recommend?
What does the Dependency Inversion Principle (DIP) recommend?
Flashcards
Interfaces
Interfaces
Declare intent, define functions implemented by classes.
Abstract Classes
Abstract Classes
Declare intent and incorporate implementations, useful as extension points
Encapsulation
Encapsulation
Public, protected or private functions and data members
Inheritance
Inheritance
Signup and view all the flashcards
Overriding
Overriding
Signup and view all the flashcards
Good Design
Good Design
Signup and view all the flashcards
Separation of Concerns
Separation of Concerns
Signup and view all the flashcards
Module
Module
Signup and view all the flashcards
Coupling
Coupling
Signup and view all the flashcards
Cohesion
Cohesion
Signup and view all the flashcards
Law of Demeter
Law of Demeter
Signup and view all the flashcards
Single Responsibility
Single Responsibility
Signup and view all the flashcards
Open-Closed Principle
Open-Closed Principle
Signup and view all the flashcards
Liskov Substitution
Liskov Substitution
Signup and view all the flashcards
Interface Segregation
Interface Segregation
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.