Review of OOP Terms
We are currently focused on classes.
Classes are the foundation of object oriented programming.
Classes are the C++ way to implement an object.
What is an
object
?
An object is a entity that has state, behavior and identity. (Object Oriented Analysis and Design.)
An object is a run-time instance of a class. (Object Oriented Software Construction)
Our book fails to define object.
In a real sense, an object is a "thing" that we wish to use in a program.
It contains a state
The condition of the object.
These are the variables.
It contains a set of actions that can be performed
The things you can do with/to the item we are modeling.
These are the methods or functions.
Finally it exists
Probably electronically
Some things are not objects.
Selection sort is not an object
It does not have data.
It is just an algorithm
red is not an object
it is just a data value.
There are no operations on red.
Don't go too deep here.
So a
class
in c++ is the programming construct that can be used to represent an abstract data type.
And an
abstract data type
is ... A data type whose properties (domain and operations) are specified independently of any particular implementation.
Classes are composed of
members
which define the properties
A member is a component of a class
There can be member functions (the operations)
There can be member data (the domain)
A
class instance
is a variable of the class type.
The class definition is a prototype, template or plan
This tells the compiler
how
to create an instance of the class.
By declaring an
instance
of the class we build an object.
The
class constructor
is invoked to assign the state.
A
client
is the software that declares and manipulates objects of a class.
Note that we have moved away from the final user of the software.
Syntax
class identifier { accessModifier: MemberList; accessModifier: MemberList; ... };
The access modifier are
public
members are available to client code.
private
members are only available to class instances.
This is somewhat false, but will do until next semester.
Informally a
MemberList
consists of
Variable definitions
Function Prototypes
Again, there can be more here, but this will do until next semester.
Classes have five different types of member functions
Constructors
Destructors
Observers (getters)
Transformers (setters)
Iterators
Class Scope
Members of a class are in scope or visible to all other members
And all other instances of the class.
The book discusses a few topics that we have hit on informally in the past.
Information Hiding
The encapsulation and hiding of implementation details to keep the user of an abstraction from depending on or incorrectly manipulating these details.
How is this related to an ADT?
How do we practice information hiding in c++?
The private section of a class.
Placing header and code in different files.
Why do we practice information hiding?
Encapsulation?
Designing a class so that its attributes are isolated from the actions of external code except through the formal interface (book)
The bundling of data and methods. (a more generic term)
Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior. (OO Analysis and Design)
Encapsulation is sometimes used as a synonym for information hiding (OO Software Construction)
In general, I prefer the second one, but add that this is to facilitate information hiding.