CPS120: Introduction to Computer Science - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

CPS120: Introduction to Computer Science

Description:

CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts – PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 18
Provided by: wcc81
Learn more at: http://space.wccnet.edu
Category:

less

Transcript and Presenter's Notes

Title: CPS120: Introduction to Computer Science


1
CPS120 Introduction to Computer Science
  • Lecture 16A
  • Object-Oriented Concepts

2
The Procedural Paradigm
  • The functions and algorithms are the focus, with
    data viewed as something for the functions to
    manipulate

3
Object-Oriented Paradigm
  • Data should be placed inside the objects and that
    these objects should communicate with each other
    in the form of messages

4
OOP
  • Object-oriented programming (OOP) is the process
    of developing programs using the object-oriented
    paradigm

5
Classes
  • The definition of an object is know as a class
  • It is similar to using basic data structures in
    C
  • When you declare an object, you are said to have
    instantiated it (given it instances)
  • Objects are members of a class
  • Paul Millis, George Bush and George Washington
    being members of the human being class
  • The design of a class is as important as its
    implementation

6
Including Classes in C
  • For classes, the include directive uses
    different punctuation for header (.h) files
  • Quotation marks are used when the header file is
    a source file in the same location as the program
    source code
  • Angle brackets are used when the header file is
    one of the compiler's pre-compiled library
    functions

7
Using Header Files for Classes
  • Header files normally contain declarations of
    variables, functions and classes, but not
    implementations of the functions and classes

8
Designing a Class
  • Think in an object-oriented way
  • E.g. an answering machine encapsulates the
    functions of an answering machine with the data
    (messages).
  • The buttons are the equivalent of sending
    messages to the machine

9
Defining a Class
  • Functions and variables that are prototyped and
    declared in a class definition are called members

10
Public vs Private
  • Private cannot be accessed outside the object
  • Public Can have access to all the variables and
    functions

11
Constructors
  • Allow all data encapsulated within an object to
    be initialized to preset values so that errors
    can be avoided

12
Member Functions
  • Provide a way for a programmer to pass data to
    and get data from an object
  • Implemented like a normal C function
  • Except -- The class name and the scope-resolution
    operator ( ) precede the function name
  • circle circle() // default constructor

13
OOP Advantages Reusability
  • Reusability is a major benefit of object-oriented
    programming

14
OOP Advantages Containment
  • Containment is a term used to describe an object
    that contains one or more objects as members
  • (Passes the 'has-a' rule)

15
OOP Advantages Inheritance
  • Inheritance is the term used to describe an
    object that inherits properties from another
    object
  • (Passes the 'is-a' rule)
  • The class from which an object inherits
    properties is called a parent class or base class
  • The class that inherits the properties is called
    a child class or derived class

16
Multi-level Inheritance
  • Inheritance can be multi-level (i.e. from
    grandparents)

17
Multiple Inheritance
  • Objects can inherit properties form multiple
    objects
  • Multiple inheritance should be used sparingly
Write a Comment
User Comments (0)
About PowerShow.com