Lecture 1
Lecture 1
COURSE OUTLINE
Course Code: Credits: Prerequisites: Text Book
C++ How to Program, Deitel and Deitel, 7th Edition, ISBN-10: 013-611726-0, Prentice Hall, 2009 References
Object Oriented Programming with C++, Robert Lafore, 4th Edition,
ISBN-10: 0-672-32308-7, Sams, 2002 The complete Reference C++, Herber Schildt, 3rd Edition The Unified Modeling Language User Guide, Booch, Rumbaugh, Addison- Wesley, ISBN-10: 0-321-26797-4, 2nd Edition, 2005
COURSE OUTLINE
Introduction: Procedural versus Object Oriented
Programming (OOP), characteristics of OOP, advantages of OOP, Abstract Data Types (ADT), information hiding, encapsulation. Classes and Objects: Classes, objects, access specifiers, data members, member functions, properties, getters and setters, object aggregation. Constructors and Destructors: Default constructors, overloaded constructors, copy constructor, conversion constructor, shallow vs. deep copy.
COURSE OUTLINE
Static Members: Static data members and static
member functions. Generic Programming and Overloading: Function overloading, operator overloading, templates, C++ standard template library (STL). Dynamic memory management for objects: Pointers to objects, reference variables
COURSE OUTLINE
Inheritance and Polymorphism: Inheritance, types
of inheritance, derived classes, function overriding, dynamic binding, polymorphism, virtual functions. Streams and Files: Stream classes, File objects, File operations with streams. Object-Oriented Design: Introduction to Unified Modeling Language (UML).
Evaluation Methods:
Assignments
Quizzes Midterm exams Final Exam Lab Project
Global data is allowed Access to data by multiple functions means many connections between functions Programs become difficult to understand, modify and maintain
Real world things are integral collections of data and functions e.g. a car: has data (make, model etc.) and functions (acceleration) Procedural languages do not tie up data with functions
{
Properties (ingredients)
Methods (actions)
1. Gather ingredients Flour, butter, egg, sugar etc 2. preheat oven to 350 degree 3. beat eggs and butter 4. add sugar 5. mix 6. bake 10 mins
Function
Function
Function
Function
GOAL OF OOP
Clearer,
OBJECT-ORIENTED LANGUAGES
C++ Most widely used Largest programmer base Java Lacks certain features, e.g. multiple inheritance, pointers, templates Less powerful than C++ (but more safe, of course) C# Emerging Will be covered later in PLE course
THE OO APPROACH
The fundamental idea is to combine into a single
unit both data and functions that operate on the data. Such a unit is called an Object. An objects functions are called member functions in C++ And its data is called data members.
THE OO APPROACH
An objects data is typically accessed through its
member functions, i.e. it is hidden from accidental alteration Data and its function are said to be encapsulated into a single entity Data encapsulation and data hiding are key elements of object-oriented languages
THE OO APPROACH
If you want to modify data in an object, you know
exactly what functions interact with it (i.e. the member functions of the object). This simplifies writing, debugging, and maintaining the programs An OO program consists of a number of objects which communicate with each others member functions
Data
Member Function Member Function object
object
Data
Member Function
Member Function
CHARACTERISTICS OF OO LANGUAGES
Objects
Classes Encapsulation Inheritance Polymorphism and overloading
CLASSES
Objects belong to classes A class and an object of that class has the same
relationship as a data type and a variable All objects with the same characteristics (data and functions) constitute one class. A class serves only as a plan, or a template, or sketchof a number of similar things It merely specifies what data and what functions will be included in objects of that class.
CLASSES
Declaring a class doesnt create any objects, just as
mere existence of data type int doesnt create any variables. A class is thus a description of a no. of similar objects. For instance, HUMAN is a class, and JOHN is its instance (object)
Encapsulation
Information hiding
Encapsulation is the mechanism that binds together
code and the data it manipulates, and keep both safe from outside inteference and missuse
object Data Member Function Member Function object Data Member Function Member Function
INHERITANCE
Derive other (sub-)classes from an existing class The original class is called the BASE CLASS; the others
are DERIVED CLASSES Each class shares common characteristics with the class from which it was derived, and can also add its own modifications, additions. For instance, VEHICLE is a class from which CAR, TRUCK, BUS, MOTORCYCLE classes can be derived.
INHERITANCE
Base class
Feature A F F Feature B
Feature A F Feature B F
Feature A F Feature B F
Feature D F
Feature F F Feature E F
Derived classes
operators or functions in different ways depending on what they are operating on is called polymorphism (lit. one thing with several distinct forms) Overloading is a special case of polymorphism, e.g. +, -, /, << etc.