c++slides Basics And advance

Embed Size (px)

Citation preview

  • 7/27/2019 c++slides Basics And advance

    1/13

    OBJECT-ORIENTED

    PROGRAMMING (OOP) WITH

    C++

    Instructor: Dr. Hany H. Ammar

    Dept. of Electrical and Computer

    Engineering, WVU

  • 7/27/2019 c++slides Basics And advance

    2/13

    Introduction To OOP

    OOP is an approach for writing software in which data and behaviorare

    packaged together as classes whose instancesare objects

    A class is a named software representation for an abstraction, where

    An abstractionis a named collection of attributes and behavior relevant to

    modeling a given entity for some particular purpose,

    An objectis a distinct instance of a given class that is structurally identical to

    all other instances of that class.

    Software code in OOP is written to define classes, instantiate objects, and

    manipulate these objects.

  • 7/27/2019 c++slides Basics And advance

    3/13

    Abstraction

  • 7/27/2019 c++slides Basics And advance

    4/13

    Mapping Abstractions

  • 7/27/2019 c++slides Basics And advance

    5/13

    Class Structure

  • 7/27/2019 c++slides Basics And advance

    6/13

    Object Structure

  • 7/27/2019 c++slides Basics And advance

    7/13

    Summary of the Course

    This is a project-based, lab-oriented course aimed at learning the fundamentals

    of Object-Oriented Program development in C++. Topics include

    1. Object-Oriented programming concepts

    2. The C++ Program Structure

    3. The C++ Data Types

    4. Functions, Scope, and the Free Store

    5. The C++ class

    6. Operator Overloading

    7. Class Derivation and inheritance

    8. Multiple inheritance, and polymorphism

    9. Object-Oriented Analysis and Design

    10 OOP testing techniques

  • 7/27/2019 c++slides Basics And advance

    8/13

    Basic Concepts of OOP

    1. Simulating the behaviorof objects ( e.g...., an array of data structures can be

    sorted or indexed, a stack can be used for pushing or popping data). OOP

    concepts are based on the concepts of Computer Simulation.

    2.Abstract Data Types (ADTs) consists of {data structures + operations orfunctions}, (e.g....., a Matrix can be defined as an ADT consisting of a 2-

    dimensional array + the operations of inverse, transpose, and other operations

    and methods which can be applied to objects of type Matrix).

    3. Hiding implementation details using encapsulation, where each class of objects

    consists ofaprivate section, aprotectedsection, and apublic section. Data

    structures and functions in a private class section can only be accessed locally

    within the class. The protectedclass section can also be accessed by derived

    classes.

  • 7/27/2019 c++slides Basics And advance

    9/13

    Basic Concepts of OOP

    4. Reusing code through inheritance.A hierarchy of classes allow derived classes

    to inherit code (i.e.., data structures and functions) defined inparent classes.

    For example,

    Singular Nonsingular

    Square

    Matrix

  • 7/27/2019 c++slides Basics And advance

    10/13

    Basic Concepts of OOP

    5.Function and Operator Overloading. A class may contain several functions

    with the same function name but with different arguments, or operators such as

    + , -, *, and / are used to define operations on different objects, e.g.... matrix

    multiply can be defined as A * B, where A and B are objects of type Matrix.

    6.Polymorphism where objects of distinct classes can be manipulated using only

    knowledge of their common properties without regard for their exact class.

  • 7/27/2019 c++slides Basics And advance

    11/13

    Basic Concepts of OOP

    * The dynamic binding mechanism determines the type of the object and maps the

    invocation to the correct method in class X, if the object is of class X, or to the

    correct method in class Y, if the object is of class Y (e.g., the function F() could be a

    print() function, and the algorithm is unaware of the exact type of object to be printed, it

    invokes the function using a base class of classes X and Y).

  • 7/27/2019 c++slides Basics And advance

    12/13

    Basic Concepts of OOP

    7. The use oftemplates to design generic classes of objects

  • 7/27/2019 c++slides Basics And advance

    13/13

    Basic Concepts of OOP

    8. The use offriend functions andfriend classes to access all the functions and

    data types of other classes (violates the concept of information hiding; adds

    needed flexibility and should only be used when necessary).

    9. Design using Class Libraries andDesign Patterns