DOC PREVIEW
UT Dallas CS 4337 - Chapter13 Class1 - OOP access specifier, constructor destructor - July 7, 2015

This preview shows page 1-2-3-4-5-39-40-41-42-43-44-78-79-80-81-82 out of 82 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 82 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

PowerPoint Presentation13.1Procedural and Object-Oriented ProgrammingLimitations of Procedural ProgrammingObject-Oriented Programming Terminology7/07Classes and ObjectsSlide 8More on Objects13.2Introduction to ClassesClass ExampleAccess SpecifiersSlide 14More on Access SpecifiersUsing const With Member FunctionsDefining a Member FunctionAccessors and Mutators (getter & setter)13.3Defining an Instance of a ClassSlide 21Slide 22Slide 23Slide 24Avoiding Stale DataPointer to an ObjectDynamically Allocating an Object13.4Why Have Private Members?Slide 3013.5Separating Specification from Implementation13.6Inline Member FunctionsRectangle Class with Inline Member FunctionsTradeoffs – Inline vs. Regular Member Functions13.7ConstructorsSlide 39Slide 40Slide 41Slide 42Default Constructors13.8Passing Arguments to ConstructorsSlide 46Using Default ArgumentsClasses with No Default Constructor13.9DestructorsSlide 51Slide 52Slide 53Slide 54Constructors, Destructors, and Dynamically Allocated Objects13.10Overloading ConstructorsSlide 58Slide 59Only One Default Constructor and One DestructorMember Function Overloading3.11Using Private Member Functions13.12Arrays of ObjectsSlide 66Slide 67Slide 68Slide 69Accessing Objects in an ArraySlide 71Slide 7213.15The Unified Modeling LanguageUML Class DiagramExample: A Rectangle ClassUML Access Specification NotationUML Data Type NotationUML Parameter Type NotationUML Function Return Type NotationThe Rectangle ClassShowing Constructors and DestructorsCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Chapter 13:Introduction to ClassesCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.13.1Procedural and Object-Oriented ProgrammingCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Procedural and Object-Oriented Programming•Procedural programming focuses on the process/actions that occur in a program•Object-Oriented programming is based on the data and the functions that operate on it. Objects are instances of ADTs that represent the data and its functionsCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Limitations of Procedural Programming•If the data structures change, many functions must also be changed•Programs that are based on complex function hierarchies are:–difficult to understand and maintain–difficult to modify and extend–easy to breakCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Object-Oriented ProgrammingTerminology•class: like a struct (allows bundling of related variables), but variables and functions in the class can have different properties than in a struct•object: an instance of a class, in the same way that a variable can be an instance of a structCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.7/07Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Classes and Objects•A Class is like a blueprint and objects are like houses built from the blueprintCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Object-Oriented ProgrammingTerminology•attributes: members of a class •methods or behaviors: member functions of a classCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.More on Objects•data hiding: restricting access to certain members of an object•public interface: members of an object that are available outside of the object. This allows the object to provide access to some data and functions without sharing its internal details and design, and provides some protection from data corruptionCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.13.2Introduction to ClassesCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Introduction to Classes•Objects are created from a class•Format:class ClassName{declaration;declaration;};Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Class ExampleCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Access Specifiers•Used to control access to members of the class•public: can be accessed by functions outside of the class•private: can only be called by or accessed by functions that are members of the classCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Class ExamplePrivate MembersPublic MembersCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.More on Access Specifiers•Can be listed in any order in a class•Can appear multiple times in a class•If not specified, the default is privateCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Using const With Member Functions•const appearing after the parentheses in a member function declaration specifies that the function will not change any data in the calling object.Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Defining a Member Function•When defining a member function:–Put prototype in class declaration–Define function using class name and scope resolution operator (::)int Rectangle::setWidth(double w){width = w;}Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Accessors and Mutators (getter & setter)•Mutator: a member function that stores a value in a private member variable, or changes its value in some way•Accessor: function that retrieves a value from a private member variable. Accessors do not change an object's data, so they should be marked const.Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.13.3Defining an Instance of a ClassCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Defining an Instance of a Class•An object is an instance of a class•Defined like structure variables:Rectangle r;•Access members using dot operator:r.setWidth(5.2);cout << r.getWidth();•Compiler error if attempt to access private member using dot operatorCopyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Program 13-1 (Continued)Copyright © 2012 Pearson Education, Inc.Copyright © 2012 Pearson Education, Inc.Program 13-1 (Continued)Copyright © 2012 Pearson Education,


View Full Document

UT Dallas CS 4337 - Chapter13 Class1 - OOP access specifier, constructor destructor - July 7, 2015

Download Chapter13 Class1 - OOP access specifier, constructor destructor - July 7, 2015
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter13 Class1 - OOP access specifier, constructor destructor - July 7, 2015 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter13 Class1 - OOP access specifier, constructor destructor - July 7, 2015 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?