1/75
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Object Oriented Design (OOD)
A problem solving methodology
Objects
Components of a solution
Class
A collection of a fixed number of components
Member
Component of a class
Class Definition
Defines a data type; no memory is allocated
Class member
Can be a variable or a function
Variable member of a class
It's declared like any variable; you cannot initialize a variable when you declare it
Function member of a class
Function prototype is listed; function members can (directly) access any member of the class
Private member
Member cannot be accessed outside of class
Public member
Member that can be accessed outside of class
Protected member
Member that can be accessed by derived classes
Unified Modeling Language
Used to graphically describe a class and its members
Class variable
Called a class object or class instance
Member access operator
The dot (.) is used to access class members
Automatic object
Created when the declaration is reached and destroyed when the surrounding block is exited
Static object
Created when the declaration is reached and destroyed when the program terminates
Passing by value
Contents of data members of the actual parameter are copied into the corresponding data members of the formal parameter
Passing by reference
The formal parameter receives only the address of the actual parameter
Const in formal parameter
Used to prevent changes to the actual parameter when passing by reference
Accessor Function
Member Function that only accesses the value(s) of member variable(s)
Mutator Function
Member Function that modifies the value(s) of member variable(s)
Constant Function
Member Function that cannot modify member variables
Instance Variables
Each object has its own copy of the member variables (hr, min, sec)
Scope resolution operator
Used to access identifiers local to the class
Client of a class
A program that uses/manipulates objects of a class
Public member
Member can be accessed outside of class
Protected member
Member can be accessed by derived classes
Member access operator
The dot (.) is used to access members of a class
Constant Function
Member Function that cannot modify member variables; use const in function heading
Order of Members
C++ has no fixed order in which to declare private and public functions.
Default Member Access
By default, all members of a class are private.
Public Member Access
Use the member access specifier public to make a member available for public access.
Constructors
Use constructors to guarantee that member variables of a class are initialized.
Types of Constructors
Two Types of Constructors: a) Default Constructor (no parameters), b) Parameterized Constructor (with parameters).
Constructor Naming
Name of Constructor = Name of the Class.
Constructor Type
A constructor has no type.
Multiple Constructors
A class can have more than one constructor; each must have a different formal parameter list.
Constructor Execution
Constructors execute automatically when a class object enters its scope.
Constructor Invocation
A constructor is automatically executed when a class variable is declared.
Specific Constructor Invocation
Because a class may have more than one constructor, you can invoke a specific constructor.
Default Constructor Invocation Syntax
To invoke the default constructor: className classObjectName.
Parameterized Constructor Invocation Syntax
Syntax: className classObjectName (argument1, argument2, ...).
Argument Matching
Number and type of arguments should match the formal parameters of one of the constructors.
Type Conversion
Otherwise, C++ uses type conversion and looks for the best match; any ambiguity causes a compile-time error.
Default Parameters in Constructors
Constructor can have default parameters; rules for declaring formal parameters are the same as for declaring default parameters in a function.
Default Constructor Definition
A constructor with no parameters or with all default parameters.
Default Constructor Provision
If a class has no constructor(s), C++ provides the default constructor; however, the object declared is still uninitialized.
Absence of Default Constructor
If a class includes constructors(s) with parameter(s), but not the default constructor, C++ does not provide the default constructor.
Array of Class Objects
If you declare an array of class objects, the class should have the default constructor.
Destructor
Functions without any type.
Destructor Naming
Name of a destructor is the character "~" followed by the class name (ex: ~clockType).
Single Destructor
A class can only have one destructor; the destructor has no parameters.
Destructor Execution
Destructor automatically executes when class object goes out of scope.
Abstraction
Separating design details from usage; separating the logical properties from the implementation details.
Abstract Data Type (ADT)
Data type that separates the logical properties from the implementation details.
Struct vs Class
By default, members of a struct are public; private specifier can be used in a struct to make a member private.
Members of Class
By default, members of a class are private.
Capabilities of Classes and Structs
Classes and structs have the same capabilities.
Expanded Struct Definition
In C++, the definition of a struct was expanded to include member functions, constructors, and destructors.
Using Struct
If all member variables of a class are public and there are no member functions, use a struct.
Information Hiding
Hiding the details of the operations on the data.
Interface
Contains the specification details.
Implementation File
Contains the implementation details (file extension is .cpp).
Function Prototypes in Header
In header file, include function prototypes and comments that briefly describe the functions.
Precondition
A statement specifying the condition(s) that must be true before the function is called.
Postcondition
A statement specifying what is true after the function call is completed.
Static Members
Use the keyword static to declare a function or variable of a class static.
Accessing Static Members
A public static function or member of a class can be accessed using the class name and the scope resolution operator.
Static Member Variables
Static member variables of a class exist even if no object of that class type exists.
Non-static Member Variables
Multiple objects of a class each have their own copy of non-static member variables.
Shared Static Members
All objects of a class share any static member of the class.
Class Summary
Class: collection of a fixed number of components.
Class Members
Members: components of a class; accessed by name; 3 Categories: public, private, protected.
Class Variables
Class variables are called class objects or simply objects.
Built-in Operations on Classes
The only built-in operations on classes are assignment and member selection.
Instance Variables
Instance variables: non-static data members.