Classes
Classes
Purpose of Program
Quality
Maintenance
ABSTRACTION vs ENACPSULATION
SPECIFICATION & INTERFACE
Data type
Objects
Operations
ABSTRACT DATA TYPE
ADT
Program
Classes: Definitions
- Private
# protected
+ public
Object Declaration & Memory
Allocation
Memory is allocated only when the object is declared.
Object aka instance
Compute memory required for the class clockType.
Class Object Diagram
Accessing Class Members & what can
you access
Can & CanNOT
Functions
Behavior
Interface
BUT IT IS STILL ONE TASK PER FUNCTION ONLY
Implementation of Functions
Constructor
Properties
Why would you need a constructor in the first place?
Types of constructors
Default constructor
Parameterized constructor
Fully parameteized constructor
Constructor with default parameters
Copy constructor
Default Parameters in Constructors
Special copy constructor
When declaring a class object, you can initialize it by using the value of
an existing object of the same type.
Using copy constructors
Invoking constructor
Note regarding constructors
clockType arrivalTimeEmp[100];
Class with pointers
Using assignment operator
shallow copy
Write copy constructor to achieve this
Destructor
}
Struct vs Classes
“clockType.h”
Containing declaration of class and its memberlist
“clockType.cpp”
Containing the definition of the functions
Main
Containing the main part where the objects are declared and the interfaces re
used
Upcasting and downcasting
Upcasting
When you use upcasting, the object is not changing. Nevertheless, when
you upcast an object, you will be able to access only member functions
and data members that are defined in the base class:
Upcasting
his function will work with all the classes that are derived from the
Employee class. When you call it with objects of type Manager and
Person, they will be automatically upcasted to Employee class:
Pointers to class
some pointer and class operators
(*, &, ., ->, [ ])
Operator Overloading
Operator Overloading: format, MUST
DOs & Restrictions
clockType
Overload the following operators
Assignment (=)
Copies the values of one object of clockType into another
Not equal to (!=)
Return true if both objects are not equal
Difference (-)
Computes a valid difference between two objects
Addition (+)
Adds the two times of clocks and return a valid object of clock
Hash (#)
validates if the given clock object is valid or not.
Streams overloading: cin, cout