1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Programming in C++ - Chapter 14: Object oriented design

32 81 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 32
Dung lượng 541,88 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Lecture Programming in C++ - Chapter 14: Object oriented design. In this chapter, you will learn how to: Use the special class specifiers static and const, work with friend functions and classes, read some UML and the difference between has a and uses relationships.

Trang 1

Design

Trang 3

Member function automatically called when object goes out of scope

Trang 4

Access allowed from file with declaration – static used with data member of a class

access allowed by all objects of the class Lesson 14.2

Trang 5

 Accessible and modifiable by invoking  static  member function on class

 Specified as  public or private in accessibility Lesson 14.2

Trang 6

 Allowed to be called even when no class objects 

exist in program

Lesson 14.2

Trang 7

Data members and objects qualified by const cannot be modified after 

initialization

Function members qualified with const 

do not modify invoking object's data

Lesson 14.3

Trang 8

– Using const before and after the data 

type

 Neither value pointed to nor address stored  can be modified

Lesson 14.3

Trang 10

Protects data members from being 

inadvertently modified

To declare function (with 2 arguments) const        type function  (type, type) const;

Form of declarator for above function

type Class  :: function (type arg1, type arg2) const

Lesson 14.3

Trang 11

Effectively makes all data members const

– None of data members of const object can be  changed after initialization

Form:  declare const object with 3 arguments      const  Class object (arg1, arg2, arg3);

Can use const object to call function

      object.function (arg1b, arg2b);

Lesson 14.3

Trang 12

Lesson 14.3

Trang 13

       friend  type  function (type, type);

Lesson 14.4

Trang 14

Defining friend functions

– Keyword not used in function definition – Directly accesses private data members of  object (where class declared friend)

Calling friend functions

– No invoking object used since friend not a  member function

     function  (arg1, arg2);

Lesson 14.4

Trang 15

granting class Friend function(nonmember)

Trang 16

};

Trang 17

All member functions of friend class can access all private data and function member 

Trang 19

– objectg is the granting class object

Lesson 14.5

Trang 20

Lesson 14.6

Trang 21

Generated by the operator expression

Dependent upon classification of the 

operator function being friend or member, binary or unary

– Binary friend functions

– Binary member functions

– Unary member functions

– Unary friend functions (not commonly used) Lesson 14.6

Trang 23

Placeholder (any binary operator +, ­, =,*, or /

Trang 24

Additional complication of being either prefix or postfix

Trang 26

 Equivalent function call for each operator cannot 

be modified

Lesson 14.6

Trang 27

Lesson 14.6

Trang 28

Unified Modeling Language

Developed by James Rumbaugh, Grady Booch, and Ivar Jacobson in mid 1990sCreate diagrams to develop program

Trang 29

 Rectangles used to enclose classes

 Lines used to connect classes that interact

 Arrows and descriptors used to indicate type and  direction of interaction

Trang 30

class

Trang 31

"uses" or client­server relationship

Keeps server class independent of client class Has simple interface between the two classesServer class designer must create both 

interface and implementation

Lesson 14.7

Trang 32

Use the special class specifiers static and const

Ngày đăng: 30/01/2020, 00:16

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN