Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science Department University of California, Davis

Similar presentations


Presentation on theme: "Computer Science Department University of California, Davis"— Presentation transcript:

1 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 10/07/2011 ecs40 fall 2012

2 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

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

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

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

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

7 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

8 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

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

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

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

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

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

14 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

15 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

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

17 # 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

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

19 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

20 10/07/2011 ecs40 fall 2012

21 10/07/2011 ecs40 fall 2012

22 10/07/2011 ecs40 fall 2012

23 10/07/2011 ecs40 fall 2012

24 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.

25 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.

26 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

27 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

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

29 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

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

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

32 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

33 10/07/2011 ecs40 fall 2012

34 10/07/2011 ecs40 fall 2012

35 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


Download ppt "Computer Science Department University of California, Davis"

Similar presentations


Ads by Google