Chapter 10 Classes and Objects - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Chapter 10 Classes and Objects

Description:

A class provides the foundation for creating specific objects, each of which ... implementation level, a class is a syntactical unit that describes a set of data ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 21
Provided by: csCham
Category:

less

Transcript and Presenter's Notes

Title: Chapter 10 Classes and Objects


1
Chapter 10 Classes and Objects
CS240-Intermediate Programming
Created by Andrew StaugaardModified by Dr.
Martins
  • Chaminade University of Honolulu
  • Department of Computer Science

2
Definitions
  • A class provides the foundation for creating
    specific objects, each of which shares the
    general attributes, or characteristics, and
    behavior of the class.
  • At the abstract level, a class can be described
    as an interface that defines the behavior of its
    objects.
  • At the implementation level, a class is a
    syntactical unit that describes a set of data and
    related operations that are common to its
    objects.

3
Chapter 10
  • CLASS DECLARATION FORMAT
  • class name
  • //FUNCTION MEMBERS
  • public
  • Function prototypes go here.
  • //DATA MEMBERS
  • private
  • Variable definitions go here.
  • //END CLASS

4
Chapter 10
  • The public class functions form the interface to
    the class and are accessible from outside the
    class.
  • Public functions are used to provide access to
    and manipulate the private class members.
  • A private class member is only accessible within
    the class by functions of the same class.

5
Encapsulation
  • Encapsulation means to package data and/or
    operations into a single well-defined programming
    unit.

6
Information hiding
  • Information hiding means that there is a binding
    relationship between the information, or data,
    and its related operations so that operations
    outside the encapsulated unit cannot affect the
    information inside the unit.

7
Unified Modeling Language
  • The Unified Modeling Language, or UML, is a
    technique for analyzing and designing
    object-oriented software.

8
Chapter 10
  • UML diagram for a SavingsAccount class

9
Object
  • An object is an instance, or specimen, of a given
    class.
  • An object of a given class has the structure and
    behavior defined by the class that is common to
    all objects of the same class.

10
Chapter 10
  • Object Definition Format
  • class name object name

11
A function implementation
  • A function implementation is the definition of
    the function that includes the function header
    and the body of the function.

12
Chapter 10
  • Format for a Function Implementation
  • return type class name function name
    (parameter listing)
  • //BODY OF FUNCTION GOES HERE
  • //END FUNCTION

13
Constructors
  • A constructor is a special class function that is
    used to initialize an object automatically when
    the object is defined.

14
Constructor Format
15
Chapter 10
  • All the member functions of a class carry with
    them an invisible pointer, called this, that
    points to the object that called the function.

16
Access Functions
  • An access function, sometimes called a get
    function, is a function that returns only the
    values of the private members of an object.

17
Messages
  • A message is a call to a member function.

18
Chapter 10
  • A type cast converts data of one type to a
    different type, temporarily.
  • You can convert data of one type to another type
    by preceding the data variable/expression with
    the type to convert to within parentheses like
    this
  • winPercent (double)wins/(wins losses) 100

19
Project Files
  • A project file identifies the files that need to
    be compiled and linked to create a given
    executable program.

20
A multi-file Project
Write a Comment
User Comments (0)
About PowerShow.com