Computer Science Department University of California, Davis

Slides:



Advertisements
Similar presentations
CPS 235 Object Oriented Programming Paradigm
Advertisements

ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 10: Continuing with classes Constructors, using classes.
 2003 Prentice Hall, Inc. All rights reserved. ECE 2552 Dr. S. Kozaitis Summer Summary of Topics Related to Classes Class definition Defining member.
Classes: A Deeper Look Systems Programming.  constconst  const objects and const member functions   Composition   Friendship  this  this pointer.
計算機程式語言 Lecture 10-1 國立台灣大學生物機電系 林達德 10 Classes: A Deeper Look, Part 2.
OOP Using Classes - I. Structures vs. Classes C-style structures –No “interface” If implementation changes, all programs using that struct must change.
 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 16: Classes and Data Abstraction Outline 16.1Introduction.
Classes: A Deeper Look Systems Programming.
A Deeper Look at Classes CS-2303, C-Term A Deeper Look at Classes CS-2303 System Programming Concepts (Slides include materials from The C Programming.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 4 - Classes Jan 27,
Review of C++ Programming Part II Sheng-Fang Huang.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Chapter 14 – Object Oriented Design. Copy Constructor u Called with an object as an argument u General declarator Class :: Class (Class& alias) –Class.
PART I CHAPTER 16 CS116 SENEM KUMOVA METİN 1. Structures Structures : Aggregate data types built using elements of other types struct Time { int hour;
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
More C++ Classes Systems Programming. C++ Classes  Preprocessor Wrapper  Time Class Case Study –Two versions (old and new)  Class Scope and Assessing.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Chapter 10 Classes and Objects: A Deeper Look Visual C# 2010 for Programmers © by Pearson Education, Inc. All Rights Reserved.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
C++ Lecture 4 Tuesday, 15 July Struct & Classes l Structure in C++ l Classes and data abstraction l Class scope l Constructors and destructors l.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
CLASSES : A DEEPER LOOK Chapter 9 Part I 1. 2 OBJECTIVES In this chapter you will learn: How to use a preprocessor wrapper to prevent multiple definition.
 2006 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 17 - C++ Classes: Part II Outline 17.1Introduction.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
10/18/2011ecs40 fall Software Development & Object- Oriented Programming ecs40 Fall 2012: Software Development & Object- Oriented Programming #02:
C++ Lecture 5 Monday, 18 July Chapter 7 Classes, continued l const objects and const member functions l Composition: objects as members of classes.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
Programming Techniques Classes II Important Class Features Spring 2009.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 14: More About Classes.
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
Chapter 9 Classes: A Deeper Look, Part 1 Seventh Edition C++ How to Program © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. ECE 2552 Dr. Këpuska Summer 2004 from Dr. S. Kozaitis Spring 2003 slides 1 Summary of Chapter 6: Classes.
Part -1 © by Pearson Education, Inc. All Rights Reserved.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Lecture 5: Classes (continued) Feb 1, 2005
Linked Lists Chapter 6 Section 6.4 – 6.6
Chapter 16: Classes and Data Abstraction
About the Presentations
This pointer, Dynamic memory allocation, Constructors and Destructor
Chapter 17 - C++ Classes: Part II
Object Based Programming
Chapter 9 Classes: A Deeper Look, Part 1
10.2 const (Constant) Objects and const Member Functions
Classes, Constructors, etc., in C++
7.4 friend Functions and friend Classes
Classes: A Deeper Look, Part 2
Operator Overloading Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Recitation Course 0520 Speaker: Liu Yu-Jiun.
Recitation Course 0603 Speaker: Liu Yu-Jiun.
Classes: A Deeper Look, Part 2
More C++ Classes Systems Programming.
Object Oriented Programming (OOP) Lecture No. 12
SPL – PS3 C++ Classes.
Introduction to Classes and Objects
Presentation transcript:

Computer Science Department University of California, Davis ecs40 Fall 2012: Software Development & Object-Oriented Programming midterm review Dr. S. Felix Wu Computer Science Department University of California, Davis http://www.cs.ucdavis.edu/~wu/ wu@cs.ucdavis.edu 10/07/2011 ecs40 fall 2012

Midterm – 10/23/2012 Chapters 3, 6.11, 8.9, 9, 10, plus this set of slides closed book/note/device/people test 10/07/2011 ecs40 fall 2012

An Object Integrity/Protection Reusability Abstraction 10/07/2011 ecs40 fall 2012

Memory Cell Layout main Scan_address Scanf malloc/free a.out 10/07/2011 ecs40 fall 2012

Integrity/Protection? Reusability? Abstraction? malloc free 10/07/2011 ecs40 fall 2012

Integrity/Protection Reusability Abstraction malloc free Soft shell 10/07/2011 ecs40 fall 2012

C++ GradeBook string Course name malloc/free a.out setCourseName getCourseName displayMessage Course name 7 7 malloc/free C++ a.out 10/07/2011 ecs40 fall 2012

Life cycle of an Object Memory allocation (static/dynamic) Constructor (class definition) “the working phase” The option of Persistent Objects Destructor (due to various reasons) Memory Deallocation 10/07/2011 ecs40 fall 2012

GradeBook GradeBook string Course name GradeBook setCourseName getCourseName displayMessage Course name 9 9 10/07/2011 ecs40 fall 2012

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

C++ GradeBook string Course name malloc/free a.out setCourseName getCourseName displayMessage Course name 14 14 malloc/free C++ a.out 10/07/2011 ecs40 fall 2012

Object-Oriented “Separation of Interface and Implementation” Time int Constructor Time int setTime int int printUniversal printStandard “Separation of Interface and Implementation” Time.h Time.c main.c 15 10/07/2011 ecs40 fall 2012

Time.c Time.h Time Time 10/07/2011 ecs40 fall 2012

# CFLAGS = -g –DTIME_DEBUG # rules. all: time_test # Makefile for ecs40 time # macros CC = g++ CFLAGS = # CFLAGS = -g –DTIME_DEBUG # rules. all: time_test time_test: main.o time.o $(CC) -o time_test main.o time.o main.o: main.c time.h $(CC) -c $(CFLAGS) main.c time.o: time.c time.h $(CC) -c $(CFLAGS) time.c clean: rm -f *.o *~ core ecs30b_hw2_1 10/07/2011 ecs40 fall 2012

Time_Implementation *ptr; class Time_Implementation; Time_Implementation *ptr; 10/07/2011 ecs40 fall 2012

Once class Time has been defined, it can be used as a type in object, array, pointer and reference declarations as follows: Time sunset; // object of type Time Time arrayOfTimes[ 5 ]; // array of 5 Time objects Time &dinnerTime = sunset; // reference to a Time object Time *timePtr = &dinnerTime; // pointer to a Time object 10/07/2011 ecs40 fall 2012

10/07/2011 ecs40 fall 2012

10/07/2011 ecs40 fall 2012

10/07/2011 ecs40 fall 2012

10/07/2011 ecs40 fall 2012

static Class Members Although they may seem like global variables, a class’s static data members have class scope. static members can be declared public, private or protected. A fundamental-type static data member is initialized by default to 0. If you want a different initial value, a static data member can be initialized once. A static const data member of int or enum type can be initialized in its declaration in the class definition. All other static data members must be defined at global namespace scope and can be initialized only in those definitions. If a static data member is an object of a class that provides a default constructor, the static data member need not be initialized because its default constructor will be called.

static Class Members A class’s private and protected static members are normally accessed through the class’s public member functions or friends. A class’s static members exist even when no objects of that class exist. To access a public static class member when no objects of the class exist, prefix the class name and the binary scope resolution operator (::) to the name of the data member. To access a private or protected static class member when no objects of the class exist, provide a public static member function and call the function by prefix-ing its name with the class name and binary scope resolution operator. A static member function is a service of the class, not of a specific object of the class.

Object/Class “Static members: data/method” Time shadow static int int Constructor Time shadow static getValue int int printUniversal Shared printStandard “Static members: data/method” 26 10/07/2011 ecs40 fall 2012

Static members Is it a member of an object or its class? Is a class an object itself? Is there a class called “class”? Meta-class Object-oriented: “Everything is an object!” Or, “should be” 10/07/2011 ecs40 fall 2012

Class Time Is_a_member_of myTime yourTime StrangeTime Object Object 10/07/2011 ecs40 fall 2012

Python, Ruby, Smalltalk, Objective-C Class Class Object Meta-class – capability to modify the behavior of objects of a particular class. Python, Ruby, Smalltalk, Objective-C Class Class Object Is_a_member_of Class Time Class Date Class Clock Object Object Object 10/07/2011 ecs40 fall 2012

Composite Objects Objects within an Object Clock Time Date int Constructor Clock Time setTime Date int printUniversal printStandard 10/07/2011 ecs40 fall 2012

Pointer vs. Object – but how about “C++ reference” Implementation &III; 10/07/2011 ecs40 fall 2012

Using friend functions can enhance performance. Friend Functions and Classes A friend function of a class is defined outside that class’s scope, yet has the right to access the non-public (and public) members of the class. Standalone functions, entire classes or member functions of other classes may be declared to be friends of another class. Using friend functions can enhance performance. Friendship is granted, not taken. The friendship relation is neither symmetric nor transitive. 10/07/2011 ecs40 fall 2012

10/07/2011 ecs40 fall 2012

10/07/2011 ecs40 fall 2012

this == the memory address of the first byte of this object ~ HW#2.1 this == the memory address of the first byte of this object 10/07/2011 ecs40 fall 2012