Ch01
Object-Oriented Concepts
Overview
Object-oriented concepts are foundational in programming, focusing on creating software that mirrors real-world interactions and objects.
Object-Oriented Analysis (OOA)
Purpose of OOA:
Develop an understanding of the problem rather than focus on how to solve it.
Identifies requirements of a solution and clarifies what the solution must achieve.
Generates accurate expectations from end-users regarding the solution.
Key Focus:
Identifying real-world objects and their interactions.
Emphasizes understanding the problem and the requirements within the context of the object domain.
Object-Oriented Design (OOD)
Purpose of OOD:
Describes a solution in terms of objects and their collaborations.
Collaboration Among Objects:
Collaborations must serve a specific purpose related to the requirements.
Models of solutions illustrate how objects interact by sending messages (calling methods).
Relationships focus on 'is a' and 'has a' connections among objects.
Object Characteristics
Cohesion
Definition:
Refers to the degree to which class member functions operate on data within the class.
High Cohesion:
Indicates good design; member functions operate only on class data.
Benefits:
Easy to reuse in other projects.
Easy to revise or correct issues.
Robust against changes.
Coupling
Definition:
Describes the degree of dependency among classes.
Low Coupling:
Indicates independence; preferable as it allows for easier changes and understanding of the code.
Enhances cohesion.
UML Class Diagrams:
Serve to visualize dependencies and illustrate coupling.
Module and Algorithm Design
Module Design:
Good modules must efficiently store, move, and alter data.
Modules need to communicate for effective data manipulation.
Algorithm:
A step-by-step guide to performing a task within a specified time.
Functions implement these algorithms on data collections.
Abstraction and Information Hiding
Abstraction
Definition:
Separates the purpose of a module from its implementation.
Written specifications (in C++ header files) precede implementation.
Information Hiding
Purpose:
Hides module details to prevent tampering by other modules.
Two views of a module:
Public View: Specification exposure.
Private View: Actual implementation details.
Classes in OOP
Concept:
Object-oriented languages support creating classes that encapsulate characteristics (attributes) and behaviors (methods) of objects.
Data Members:
Characteristics or attributes stored within an object.
Member Functions:
Operations typically interacting with data members.
Interfaces and Signatures
Interfaces
Definition:
Public declaration of accessible member functions; outlines how programmers interact with classes.
Design Goals:
Must be user-friendly with minimal complexity to enhance understandability.
Operation Signature
Components:
Includes name, parameters, return type, and qualifiers for member functions.
Ideally, functions do not modify parameters and return a single value.
Key Object-Oriented Programming Principles
Encapsulation:
Combines data and operations, concealing internal complexities.
Inheritance:
Allows classes to inherit properties and behaviors from other classes, promoting code reuse.
Polymorphism:
Enables objects to select appropriate operations at execution time; in C++, this often uses pointers.
Abstract Data Type (ADT)
Definition:
A collection of data along with operations that can be performed on that data, used without requiring knowledge of implementation.
Data Structure:
A construct in programming that organizes data; serves as an implementation of an ADT.