Object-Oriented Design (OOD) Concepts

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

How do objects communicate in an object-oriented system?

  • By directly accessing each other's data.
  • By using a central database for communication.
  • By sending messages through calling methods. (correct)
  • By sharing global variables.

What primarily defines the acceptable interactions with an object in object-oriented programming?

  • The object's programming language.
  • The object's methods. (correct)
  • The object's attributes.
  • The object's data types.

What is the significance of a method signature in object-oriented programming?

  • It determines the memory allocated to a method.
  • It defines the access level of a method.
  • It specifies the order in which methods are executed.
  • It provides the unique identifier of a method, including its name, parameters, and return type. (correct)

Which concept allows an object to control access to its internal state, preventing direct modification from external sources?

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

In object-oriented terms, what is the role of an 'interface'?

<p>To specify a set of method signatures that a class must implement. (B)</p> Signup and view all the answers

In the context of object interactions, which object is considered the 'server object'?

<p>The object that receives and executes the method call. (C)</p> Signup and view all the answers

What principle should guide the design of an object's interface?

<p>Creating methods based on the anticipated needs of client objects. (A)</p> Signup and view all the answers

Which of the following best describes modular programming?

<p>A design technique focused on dividing a program into independent, interchangeable parts. (A)</p> Signup and view all the answers

How do objects differ from modules in terms of data access?

<p>Objects encapsulate data to prevent misuse, while modules have loose groupings of subprograms and data. (C)</p> Signup and view all the answers

What is the primary purpose of UML (Unified Modeling Language) in object-oriented design?

<p>To provide a standard way to visualize and communicate the structure and behavior of a system. (A)</p> Signup and view all the answers

Which UML diagram is used to represent the structure of a system by showing classes, attributes, methods, and relationships?

<p>Class Diagram (A)</p> Signup and view all the answers

Which UML diagram is suited for illustrating interactions between actors and a system to achieve specific goals?

<p>Use Case Diagram (D)</p> Signup and view all the answers

If a line in a UML class diagram has an open arrowhead from Class A to Class B, what relationship is represented?

<p>Inheritance (A)</p> Signup and view all the answers

What type of relationship is depicted in UML when one object accesses another's method or attribute?

<p>Association (A)</p> Signup and view all the answers

In UML, which relationship signifies that one class is a specialized form of another class?

<p>Inheritance (C)</p> Signup and view all the answers

Which UML relationship represents a 'has-a' relationship where the child cannot exist independently of the parent?

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

What differentiates Aggregation from Composition in UML object relationships?

<p>Aggregation implies the child class can exist without the parent, while composition implies it cannot. (C)</p> Signup and view all the answers

In object-oriented design, what advantage does composition provide over inheritance regarding changes to the base class?

<p>Composition allows changes in the base class to be easily contained, minimizing impact on other classes. (C)</p> Signup and view all the answers

What is the defining characteristic of polymorphism in object-oriented programming?

<p>The ability of objects of different classes to be treated as objects of a common type. (D)</p> Signup and view all the answers

Which type of polymorphism is resolved during compile-time?

<p>Compile-time Polymorphism (A)</p> Signup and view all the answers

What is a key characteristic of runtime polymorphism?

<p>The decision about which method to call is made at runtime based on the object's type. (A)</p> Signup and view all the answers

What principle underlies 'Duck Typing'?

<p>Focusing on an object's methods and properties rather than its specific class. (D)</p> Signup and view all the answers

What is 'Subtyping' in the context of polymorphism?

<p>A type of polymorphism where code written for a supertype works on a subtype. (C)</p> Signup and view all the answers

What is the primary characteristic of ad-hoc polymorphism (method/operator overloading)?

<p>A single name or symbol having multiple implementations based on argument types. (D)</p> Signup and view all the answers

Which of the following is a potential drawback of using polymorphism in software design?

<p>Increased code complexity and difficulty in understanding which implementation will be called. (D)</p> Signup and view all the answers

How does modularity contribute to the benefits of object-oriented design?

<p>It simplifies system maintenance and understanding. (D)</p> Signup and view all the answers

What is a primary difference between process-oriented and object-oriented approaches to software design?

<p>Process-oriented is person-centric while object-oriented is organization-centric. (A)</p> Signup and view all the answers

Which key methodological factor ensures that you can trace the evolution of a software system from its initial requirements to its current implementation?

<p>Traceability (C)</p> Signup and view all the answers

In the context of software development, what does 'Testability' primarily refer to?

<p>The degree to which software can be effectively tested. (C)</p> Signup and view all the answers

What principle does Test-Driven Development (TDD) emphasize?

<p>Converting software requirements into test cases before writing the code. (D)</p> Signup and view all the answers

What does 'Measurability' refer to when designing object-oriented systems?

<p>The quantification and tracking of software quality and development productivity. (C)</p> Signup and view all the answers

Why is security a critical consideration in object-oriented design?

<p>To protect against vulnerabilities and unauthorized access. (B)</p> Signup and view all the answers

What potential conflict might arise when considering security in system design?

<p>Security needs may sometimes conflict with other requirements like ease of use. (C)</p> Signup and view all the answers

What does it mean when an object is described as having a specific 'interface'?

<p>The object has a defined set of methods that specify how it can be interacted with. (D)</p> Signup and view all the answers

Considering the principles of object-oriented programming, if a 'Car' class and a 'Truck' class both inherit from a superclass called 'Vehicle', what concept allows you to treat both 'Car' and 'Truck' objects uniformly as 'Vehicle' objects?

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

What is the key goal of dividing a software program into modules?

<p>To separate the functionality of the program into independent, manageable parts. (C)</p> Signup and view all the answers

Which of the following describes a situation where composition would be preferred over inheritance?

<p>When you want to add functionality to a class without altering the base class or its interfaces. (C)</p> Signup and view all the answers

What is meant by an object encapsulating data?

<p>The object's data is protected and can only be accessed or modified through the object's methods. (A)</p> Signup and view all the answers

In the context of software design, what does 'Agility' mean?

<p>The ability to quickly adapt to changing requirements (A)</p> Signup and view all the answers

Flashcards

Object-Oriented Programming (OOP)

A programming approach centered around objects, containing data (attributes) and code (methods).

Object-Oriented Design (OOD)

Using objects and object-oriented programming to design a software solution.

Object Contents

Data (attributes, properties) and code (methods, functions) within an object.

Classes

Objects are instances of these; they determine an object's type.

Signup and view all the flashcards

Object Calling and Answering

Objects respond to messages by running methods which follow specific rules.

Signup and view all the flashcards

Methods

A named operation w/ parameters. Objects don't accept arbitrary calls.

Signup and view all the flashcards

Method signature

The signature includes its name, parameters, and type.

Signup and view all the flashcards

Object Interface

Set of method signatures for that object

Signup and view all the flashcards

Information Hiding

Hiding internal implementation details from outside access.

Signup and view all the flashcards

Messaging

Objects send messages by calling methods on other objects.

Signup and view all the flashcards

Message

The method call sent to an object.

Signup and view all the flashcards

Client Object

The object making a method call.

Signup and view all the flashcards

Server Object

The object receiving and executing a method call.

Signup and view all the flashcards

Object Interface

The set of method signatures offered by a server object.

Signup and view all the flashcards

Modular Programming

Breaking program functionality into independent, interchangeable parts.

Signup and view all the flashcards

Modules

Loose groupings of subprograms and data.

Signup and view all the flashcards

Objects

Encapsulate data and methods.

Signup and view all the flashcards

UML

How UML is used to represent data structures and relationships.

Signup and view all the flashcards

Unified Modeling Language (UML)

A standardized visual language for modeling software systems.

Signup and view all the flashcards

Class Diagrams

Represent system structure with classes, attributes and relationships.

Signup and view all the flashcards

Use Case Diagrams

Illustrate actor interactions (users, systems) to achieve goals.

Signup and view all the flashcards

UML Class Notation Compartments

Two compartments identify which are data members and operations respectively

Signup and view all the flashcards

Association

One object accesses another. Owner feeds pet.

Signup and view all the flashcards

Inheritance

An object inherits properties from another. Cat is type of pet.

Signup and view all the flashcards

Composition

Object references another as a variable. Dog has tail.

Signup and view all the flashcards

Aggregation

Child class can exist without parent.

Signup and view all the flashcards

Polymorphism

Objects handled as a common superclass.

Signup and view all the flashcards

Compile-time Polymorphism

Decision on method call is at compile time.

Signup and view all the flashcards

Runtime Polymorphism

Decision about which method to call is made at runtime.

Signup and view all the flashcards

Duck Typing

Focus on object's behavior, not type.

Signup and view all the flashcards

Subtyping

Code for supertype works on subtype. Often inheritance.

Signup and view all the flashcards

Ad-hoc polymorphism

Single name has multiple implementations based on arguments.

Signup and view all the flashcards

Static Polymorphism

Selected at compile time.

Signup and view all the flashcards

Dynamic Polymorphism

Selected at run time.

Signup and view all the flashcards

Traceability

Tracing software evolution, step-by-step.

Signup and view all the flashcards

Testability

Convert requirements to test cases first.

Signup and view all the flashcards

Measurability

Measuring software quality and productivity.

Signup and view all the flashcards

Security

Considering system security during design.

Signup and view all the flashcards

Study Notes

Object-Oriented Design (OOD)

  • Object-Oriented Programming (OOP) is a paradigm based on objects
    • Objects contain data, also known as attributes or properties
    • Objects contain code, also known as methods or functions
    • Objects are instances of classes which determine their types
  • Object-Oriented Design (OOD) is the use of objects and object-oriented programming for designing software solutions

Object Calling and Answering

  • Objects do not accept arbitrary calls
  • Acceptable calls are defined by "methods"; also known as operations, procedures, subroutines, and functions
  • Each method has its own signature, containing a name, parameters, and types

Object Interface

  • Every method has a signature
  • An object's interface is the set of method signatures for that object
  • Objects can hide their state (attributes), restricting access through an interface. This is known as Information Hiding

Client and Server Objects

  • Objects send messages by calling methods
    • The method call is identified as the message
    • The object calling the method is the client object
    • The object receiving and executing the call is the server object

Object Interfaces

  • An interface is a set of method signatures
  • Methods define the "services" a server object offers
  • An interface is a set of functional properties (services) a software object provides or requires
  • Methods/services should be created and named according to the needs of client objects intending to use them
  • On-demand design involves "pulling" interfaces and implementations based on client needs, rather than "pushing" features from a class

Modularity

  • Modular programming is a software design technique emphasizing the separation of the functionality of a program into independent, interchangeable modules (packages)

Modules vs Objects

  • Modules are loose groupings of subprograms and data
    • This "promiscuous" access to data can result in misuse
  • Objects encapsulate data

Unified Modeling Language (UML)

  • UML is a standardized visual language used in software engineering, representing different aspects of a system's structure and behavior
  • UML contains diagrams such as class diagrams, use case diagrams, sequence diagrams, activity diagrams, and state machine diagrams

Key UML Components

  • Class Diagrams: Represent the structure of a system via classes, attributes, methods, and relationships
  • Use Case Diagrams: Illustrate interactions between actors (users or external systems) and the system to achieve specific goals
  • Sequence Diagrams: Depict interactions between objects in a scenario/use case over time
  • Activity Diagrams: Model the flow of activities/actions within a system/use case
  • State Machine Diagrams: Describe the states of an object/system and the transitions between those states which are triggered by events
  • Component Diagrams: Display the components of a system and their relationships
  • Deployment Diagrams: Visualize the physical deployment of software components across hardware nodes
  • Package Diagrams: Organize and structure system elements into logical groupings

UML Class Notations

  • UML has three compartments for class notations
    • Class Name
    • Attributes
    • Operations
  • Notations include:
    • + for Public
    • - for Private
    • # for Protected
    • ~ for Package
    • / for Derived

Inheritance in UML

  • Inheritance relationships in UML diagrams show Base Classes inheriting from Derived Classes

UML Object Association

  • Association: One object accesses the other
  • Top: bidirectional association
  • Middle: Class1 accesses Class2 (unidirectional)
  • Bottom: Class1 is prohibited from accessing Class2

UML Object Inheritance

  • Inheritance (aka generalisation): An object inherits the properties of another object through class extension
  • Known as an “is a” relationship

UML Object Composition

  • Composition: An object references another object as an instance variable
  • Known as a "has a” relationship

UML Object Aggregation

  • Differentiated from composition
    • Aggregation implies the child class may exist without the parent class
    • Composition implies the child class cannot exist without the parent class
  • Some sources consider both concepts synonymous

Object Relationships - Inheritance vs Composition

  • Inheritance and composition both extend the base functionality
  • Inheritance: Changes in the "base" class propagate to the derived class and its client classes
    • Code changes risk introducing unintentional bugs
  • Composition: More adaptive to change; changes in the base class remain contained and hidden from the clients of the front-end class

Polymorphism

  • Polymorphism allows objects of different classes to be treated as objects of a common superclass
    • This invokes methods on different objects in a uniform manner, even across distinct behaviors/classes
  • Polymorphism means providing a single interface to entities of varying types, allowing entities to take on many forms

Types of Polymorphism

  • Compile-time Polymorphism (Static Binding or Early Binding)
    • Decision of which method to call occurs during compilation time
    • Method/operator overloading
  • Runtime Polymorphism (Dynamic Binding or Late Binding)
    • Decision of which method to call occurs during runtime, based on the object's type
    • Achieved through method overriding and interface implementation, redefining in a subclass which is already defined in a superclass

Duck Typing

  • Duck Typing: Object’s type/class is less important than its methods
  • "If it walks like a duck and it quacks like a duck, then it must be a duck"
  • Instead of checking types, one checks for methods/attributes

Duck Typing - Focus on Object Behaviors

  • Focuses more on behaviors vs actual type/class
  • If an object supports the necessary methods/properties for a certain operation; it is considered the expected type, regardless of its inheritance
  • Example: Iterating over collections of any type

Polymorphism and Subtyping

  • Subtyping: A type of polymorphism where code for a supertype can work on a subtype
  • Often achieved with inheritance

Polymorphism: Ad-hoc

  • Ad-hoc: involves multiple implementations
  • Also known as Method/Operator Overloading: A single name/symbol may have multiple implementations per the passed arguments

Implementation Selection in Polymorphism

  • Static: Implementation is selected at compile time
    • Called static dispatch
  • Dynamic: Implementation is selected at run time
    • Called dynamic dispatch
  • The type used depends on the programming language

Why Polymorphism?

  • Pros:
    • Allows code reuse
    • Reduces code size
    • Improves code modularity
  • Cons:
    • Can be complex
    • Makes code reading difficult, without knowing which implementation will be called
    • Dynamic dispatch is slower

Why Object-Oriented Design?

  • Modularity/reusability makes development faster and cheaper
  • Modularity also makes systems easier to maintain
  • Object-Oriented Design can be complicated to design/explain

Object-Oriented vs Process-Oriented

  • Process-oriented is easier to grasp as it is person-centric
  • Object-oriented is confusing due to labor-division (assigning tasks and coordinating workflow becomes a management concern)
  • Object-oriented is organization-centric and scales to large problems but is difficult to design

How to Design OO Systems Well?

  • Primary factors in methodology:
    • Agility (like the scrum process)
    • Traceability
    • Testability
    • Measurability
    • Security

Traceability Importance

  • It should be possible to step-by-step trace a software system from requirements to blocks of code
  • "Why is this here?" should be an answerable question
  • Good traceability ensures efficient time and resource allocation

Testability

  • Test Driven Development (TDD): Software requirements must be converted into test cases prior to software development.
  • Each step should involve a means of verification.
  • Developers must know how a software artifact will be tested before creation.
  • Continuous integration tools improve testability

Measurability

  • Measure software quality using statistics, bug reports, performance reviews and optimizations
  • Measure development productivity
    • Example: Scrum points per unit, burndown charts
  • However, performance is improved if developers are left to do their jobs

Security

  • Often critical to consider a system's security during design
  • Security issues arise from poorly designed code, exposing the system to exploits
  • Interconnectivity indicates a compromised system could affect others connected to it
  • Security requirements may create conflicts with others, such as ease of use

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