tailieunhanh - Lecture Object oriented programming - Lecture no 06

In this chapter you will learn about the following: Characteristics of users that every software engineer should understand; various ways of working with users to ensure that a software system has both the required functionality and the required usability; some basic principles for the design of simple graphical user interfaces (GUIs), involving windows, menus, icons and pop-up dialogs; how to evaluate user interfaces; how to implement basic GUIs in Java. | CSC241: Object Oriented Programming Lecture No 06 Previous Lecture Reference variable Why object pass to a function by reference const object this pointer Type of this pointer Cascading function calls Dynamic memory allocation Today’s Lecture static class member Information hiding Abstract data type (ADT) Container classes Proxy classes Object’s data member Each object of a class has its own copy of all the data members of the class 12 0 0 hours minutes seconds noon 5 50 0 hours minutes seconds wakeup static Data Members In certain cases, only one copy of a variable can be shared by all objects of a class A static data member is used If a data item in a class is declared as static, only one such item is created for the entire class, no matter how many objects are created 2 4 data1 data2 Object 1 0 static data 4 15 data1 data2 Object 2 9 3 data1 data2 Object 3 Cont. A member static variable is visible only within the class, but its lifetime is the entire program They seems like global | CSC241: Object Oriented Programming Lecture No 06 Previous Lecture Reference variable Why object pass to a function by reference const object this pointer Type of this pointer Cascading function calls Dynamic memory allocation Today’s Lecture static class member Information hiding Abstract data type (ADT) Container classes Proxy classes Object’s data member Each object of a class has its own copy of all the data members of the class 12 0 0 hours minutes seconds noon 5 50 0 hours minutes seconds wakeup static Data Members In certain cases, only one copy of a variable can be shared by all objects of a class A static data member is used If a data item in a class is declared as static, only one such item is created for the entire class, no matter how many objects are created 2 4 data1 data2 Object 1 0 static data 4 15 data1 data2 Object 2 9 3 data1 data2 Object 3 Cont. A member static variable is visible only within the class, but its lifetime is the entire program They seems like global variables It continues to exist even if there are no objects of the class A static data item is useful when all objects of the same class must share a common item of information Uses of static data member Suppose an object needed to know how many other objects of its class were in the program For example, in road-racing game a car might want to know how many other cars are still in the race In this case a static variable count could be included as a member of the class All the objects would have access to this variable Example – Race class class Race { private: static int count; int carNo; public: Race() { count++; carNo=0; } void setCarNo(int no) { carNo = no; } void printData() { cout<<“Total car = ”<< count; cout<<“,Car No. = ”<

TÀI LIỆU LIÊN QUAN
TỪ KHÓA LIÊN QUAN