Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

MATLAB
PREMIUM
Số trang
682
Kích thước
3.2 MB
Định dạng
PDF
Lượt xem
1876

MATLAB

Nội dung xem thử

Mô tả chi tiết

MATLAB®

Object-Oriented Programming

R2021a

How to Contact MathWorks

Latest news: www.mathworks.com

Sales and services: www.mathworks.com/sales_and_services

User community: www.mathworks.com/matlabcentral

Technical support: www.mathworks.com/support/contact_us

Phone: 508-647-7000

The MathWorks, Inc.

1 Apple Hill Drive

Natick, MA 01760-2098

Object-Oriented Programming

© COPYRIGHT 1984–2021 by The MathWorks, Inc.

The software described in this document is furnished under a license agreement. The software may be used or copied

only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form

without prior written consent from The MathWorks, Inc.

FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through

the federal government of the United States. By accepting delivery of the Program or Documentation, the government

hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer

software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014.

Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain

to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and

Documentation by the federal government (or other entity acquiring for or through the federal government) and shall

supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is

inconsistent in any respect with federal procurement law, the government agrees to return the Program and

Documentation, unused, to The MathWorks, Inc.

Trademarks

MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See

www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be

trademarks or registered trademarks of their respective holders.

Patents

MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for

more information.

Revision History

March 2008 Online only New for MATLAB 7.6 (Release 2008a)

October 2008 Online only Revised for MATLAB 7.7 (Release 2008b)

March 2009 Online only Revised for MATLAB 7.8 (Release 2009a)

September 2009 Online only Revised for MATLAB 7.9 (Release 2009b)

March 2010 Online only Revised for MATLAB 7.10 (Release 2010a)

September 2010 Online only Revised for Version 7.11 (Release 2010b)

April 2011 Online only Revised for Version 7.12 (Release 2011a)

September 2011 Online only Revised for Version 7.13 (Release 2011b)

March 2012 Online only Revised for Version 7.14 (Release 2012a)

September 2012 Online only Revised for Version 8.0 (Release 2012b)

March 2013 Online only Revised for Version 8.1 (Release 2013a)

September 2013 Online only Revised for Version 8.2 (Release 2013b)

March 2014 Online only Revised for Version 8.3 (Release 2014a)

October 2014 Online only Revised for Version 8.4 (Release 2014b)

March 2015 Online only Revised for Version 8.5 (Release 2015a)

September 2015 Online only Revised for Version 8.6 (Release 2015b)

March 2016 Online only Revised for Version 9.0 (Release 2016a)

September 2016 Online only Revised for Version 9.1 (Release 2016b)

March 2017 Online only Revised for Version 9.2 (Release 2017a)

September 2017 Online only Revised for Version 9.3 (Release 2017b)

March 2018 Online only Revised for MATLAB 9.4 (Release 2018a)

September 2018 Online only Revised for Version 9.5 (Release 2018b)

March 2019 Online only Revised for MATLAB 9.6 (Release 2019a)

September 2019 Online only Revised for MATLAB 9.7 (Release 2019b)

March 2020 Online only Revised for MATLAB 9.8 (Release 2020a)

September 2020 Online only Revised for MATLAB 9.9 (Release 2020b)

March 2021 Online only Revised for MATLAB 9.10 (Release 2021a)

Using Object-Oriented Design in MATLAB

1

Why Use Object-Oriented Design ................................. 1-2

Approaches to Writing MATLAB Programs ........................ 1-2

When Should You Create Object-Oriented Programs ................. 1-2

Handle Object Behavior ........................................ 1-7

What Is a Handle? .......................................... 1-7

Copies of Handles ........................................... 1-7

Handle Objects 0odified in Functions ............................ 1-8

Determine If an Object Is a Handle .............................. 1-9

Deleted Handle Objects ...................................... 1-9

Basic Example

2

Create a Simple Class .......................................... 2-2

Design Class ............................................... 2-2

Create Object .............................................. 2-3

Access Properties ........................................... 2-3

Call Methods .............................................. 2-3

Add Constructor ............................................ 2-4

Vectorize Methods .......................................... 2-4

Overload Functions ......................................... 2-5

BasicClass Code Listing ...................................... 2-6

MATLAB Classes Overview

3

Role of Classes in MATLAB ...................................... 3-2

Classes ................................................... 3-2

Some Basic Relationships ..................................... 3-3

Developing Classes — Typical :orNflow ............................ 3-6

Formulating a Class ......................................... 3-6

Specifying Class Components .................................. 3-7

BankAccount Class Implementation ............................. 3-7

Formulating the AccountManager Class ......................... 3-10

Implementing the AccountManager Class ........................ 3-11

AccountManager Class Synopsis ............................... 3-11

v

Contents

Using BankAccount Objects .................................. 3-12

Representing Structured Data with Classes ....................... 3-14

Objects as Data Structures ................................... 3-14

Structure of the Data ....................................... 3-14

The TensileData Class ....................................... 3-15

Create an Instance and Assign Data ............................ 3-15

Restrict Properties to Specific Values ........................... 3-16

Simplifying the Interface with a Constructor ...................... 3-16

Calculate Data on Demand ................................... 3-17

Displaying TensileData Objects ................................ 3-18

Method to Plot Stress vs. Strain ............................... 3-18

TensileData Class Synopsis ................................... 3-19

Implementing Linked Lists with Classes .......................... 3-23

Class Definition Code ....................................... 3-23

dlnode Class Design ........................................ 3-23

Create Doubly Linked List ................................... 3-24

Why a Handle Class for Linked Lists? ........................... 3-25

dlnode Class Synopsis ...................................... 3-25

Specialize the dlnode Class ................................... 3-34

Static Data

4

Static Data ................................................... 4-2

What Is Static Data .......................................... 4-2

Static Variable ............................................. 4-2

Static Data Object .......................................... 4-3

Constant Data .............................................. 4-4

Class 'efinLtLonރ6yntDx Reference

5

Class Files and Folders ......................................... 5-2

Class Definition Files ........................................ 5-2

Options for Class Folders ..................................... 5-2

Options for Class Files ....................................... 5-2

Group Classes with Package Folders ............................. 5-3

Class Components ............................................. 5-4

Class Building Blocks ........................................ 5-4

Class Definition Block ........................................ 5-4

Properties Block ............................................ 5-5

Methods Block ............................................. 5-5

Events Block ............................................... 5-5

A Complete Class ........................................... 5-6

Enumeration Classes ........................................ 5-6

Related Information ......................................... 5-7

vi Contents

Classdef Block ................................................ 5-8

How to Specify Attributes and Superclasses ....................... 5-8

Class Attribute Syntax ....................................... 5-8

Superclass Syntax .......................................... 5-8

Local Functions in Class File .................................. 5-9

Class Properties .............................................. 5-10

The Properties Block ....................................... 5-10

Access to Property Values .................................... 5-11

'efine Class Methods and Functions ............................. 5-13

The Methods Block ......................................... 5-13

Method Calling Syntax ...................................... 5-13

Private Methods ........................................... 5-14

More Detailed Information on Methods .......................... 5-14

Class-Related Functions ..................................... 5-14

How to Overload Functions and Operators ....................... 5-15

Rules for Defining Methods in Separate Files ..................... 5-15

Events and Listeners .......................................... 5-17

Define and Trigger Events ................................... 5-17

Listen for Events .......................................... 5-17

Attribute 6pecLficDtLon ........................................ 5-18

Attribute Syntax ........................................... 5-18

Attribute Descriptions ...................................... 5-18

Attribute Values ........................................... 5-18

Simpler Syntax for true/false Attributes ......................... 5-19

Call Superclass Methods on Subclass Objects ..................... 5-20

Superclass Relation to Subclass ............................... 5-20

How to Call Superclass Methods ............................... 5-20

How to Call Superclass Constructor ............................ 5-20

Representative Class Code ..................................... 5-22

Class Calculates Area ....................................... 5-22

Description of Class Definition ................................ 5-24

MATLAB Code Analyzer Warnings ............................... 5-27

Syntax Warnings and Property Names .......................... 5-27

Variable/Property Name Conflict Warnings ....................... 5-27

Exception to Variable/Property Name Rule ....................... 5-28

Objects In Conditional Statements .............................. 5-29

Enable Use of Objects in Conditional Statements .................. 5-29

How MATLAB Evaluates Switch Statements ...................... 5-29

How to Define the eq Method ................................. 5-30

Enumerations in Switch Statements ............................ 5-32

Operations on Objects ......................................... 5-34

Object Operations .......................................... 5-34

Help on Objects ........................................... 5-35

Functions to Test Objects .................................... 5-36

Functions to Query Class Components .......................... 5-36

vii

Use of Editor and Debugger with Classes ......................... 5-37

Write Class Code in the Editor ................................ 5-37

How to Refer to Class Files ................................... 5-37

How to Debug Class Files .................................... 5-37

Automatic Updates for 0odLfied Classes .......................... 5-39

When MATLAB Loads Class Definitions .......................... 5-39

Consequences of Automatic Update ............................ 5-39

What Happens When Class Definitions Change .................... 5-40

Ensure Defining Folder Remains in Scope ........................ 5-40

Actions That Do Not Trigger Updates ........................... 5-41

Multiple Updates to Class Definitions ........................... 5-41

Object Validity with Deleted Class File .......................... 5-41

When Updates Are Not Possible ............................... 5-41

Potential Consequences of Class Updates ........................ 5-41

Interactions with the Debugger ............................... 5-42

Updates to Class Attributes .................................. 5-42

Updates to Property Definitions ............................... 5-42

Updates to Method Definitions ................................ 5-43

Updates to Event Definitions ................................. 5-44

Compatibility with Previous Versions ............................ 5-46

New Class-Definition Syntax Introduced with MATLAB Software Version 7.6

..................................................... 5-46

Changes to Class Constructors ................................ 5-46

New Features Introduced with Version 7.6 ....................... 5-47

Examples of Old and New .................................... 5-47

Comparison of MATLAB and Other OO Languages .................. 5-49

Some Differences from C++ and Java Code ...................... 5-49

Object 0odification ........................................ 5-50

Static Properties ........................................... 5-53

Common Object-Oriented Techniques ........................... 5-53

'efinLnJ and Organizing Classes

6

8ser'efined Classes ........................................... 6-2

What Is a Class Definition ..................................... 6-2

Attributes for Class Members .................................. 6-2

Kinds of Classes ............................................ 6-2

Constructing Objects ........................................ 6-3

Class Hierarchies ........................................... 6-3

classdef Syntax ............................................. 6-3

Class Code ................................................ 6-3

Class Attributes ............................................... 6-5

Specifying Class Attributes .................................... 6-5

Specifying Attributes ........................................ 6-7

Class-Specific Attributes ...................................... 6-7

viii Contents

Evaluation of Expressions in Class 'efinLtLons ...................... 6-8

Why Use Expressions ........................................ 6-8

Where to Use Expressions in Class Definitions ..................... 6-8

How MATLAB Evaluates Expressions ........................... 6-10

When MATLAB Evaluates Expressions .......................... 6-10

Expression Evaluation in Handle and Value Classes ................ 6-10

Folders Containing Class 'efinLtLons ............................. 6-13

Class Definitions on the Path ................................. 6-13

Class and Path Folders ...................................... 6-13

Using Path Folders ......................................... 6-13

Using Class Folders ........................................ 6-14

Functions in Private Folders Within Class Folders .................. 6-14

Class Precedence and MATLAB Path ............................ 6-15

Changing Path to Update Class Definition ........................ 6-16

Class Precedence ............................................. 6-18

Use of Class Precedence ..................................... 6-18

Why Mark Classes as Inferior ................................. 6-18

InferiorClasses Attribute ..................................... 6-18

Packages Create Namespaces .................................. 6-20

Package Folders ........................................... 6-20

Internal Packages .......................................... 6-20

Referencing Package Members Within Packages ................... 6-21

Referencing Package Members from Outside the Package ........... 6-21

Packages and the MATLAB Path ............................... 6-22

Import Classes ............................................... 6-24

Syntax for Importing Classes ................................. 6-24

Import Static Methods ...................................... 6-24

Import Package Functions ................................... 6-24

Package Function and Class Method Name Conflict ................ 6-25

Clearing Import List ........................................ 6-25

Value or Handle Class — Which to Use

7

Comparison of Handle and Value Classes .......................... 7-2

Basic Difference ............................................ 7-2

Behavior of MATLAB Built-In Classes ............................ 7-2

User-Defined Value Classes .................................... 7-3

User-Defined Handle Classes .................................. 7-4

Determining Equality of Objects ................................ 7-6

Functionality Supported by Handle Classes ....................... 7-7

Which Kind of Class to Use ...................................... 7-9

Examples of Value and Handle Classes ........................... 7-9

When to Use Value Classes .................................... 7-9

When to Use Handle Classes ................................... 7-9

ix

The Handle Superclass ........................................ 7-11

Building on the Handle Class ................................. 7-11

Handle Class Methods ...................................... 7-11

Event and Listener Methods .................................. 7-11

Relational Methods ......................................... 7-12

Test Handle Validity ........................................ 7-12

When MATLAB Destroys Objects .............................. 7-12

Handle Class Destructor ....................................... 7-13

Basic Knowledge .......................................... 7-13

Syntax of Handle Class Destructor Method ....................... 7-13

Handle Object During delete Method Execution ................... 7-14

Support Destruction of Partially Constructed Objects ............... 7-15

When to Define a Destructor Method ........................... 7-15

Destructors in Class Hierarchies ............................... 7-16

Object Lifecycle ........................................... 7-16

Restrict Access to Object Delete Method ......................... 7-17

Nondestructor Delete Methods ................................ 7-18

External References to MATLAB Objects ......................... 7-18

Find Handle Objects and Properties ............................. 7-21

Find Handle Objects ........................................ 7-21

Find Handle Object Properties ................................ 7-21

Implement Set/Get Interface for Properties ....................... 7-22

The Standard Set/Get Interface ............................... 7-22

Subclass Syntax ........................................... 7-22

Get Method Syntax ......................................... 7-22

Set Method Syntax ......................................... 7-23

Class Derived from matlab.mixin.SetGet ......................... 7-23

Set Priority for Matching Partial Property Names .................. 7-27

Implement Copy for Handle Classes ............................. 7-30

Copy Method for Handle Classes .............................. 7-30

Customize Copy Operation ................................... 7-31

Copy Properties That Contain Handles .......................... 7-32

Exclude Properties from Copy ................................ 7-33

Properties — Storing Class Data

8

Ways to Use Properties ......................................... 8-2

What Are Properties ......................................... 8-2

Types of Properties .......................................... 8-2

Property Syntax ............................................... 8-4

Property Definition Block ..................................... 8-4

Access Property Values ....................................... 8-5

Inheritance of Properties ..................................... 8-5

Specify Property Attributes .................................... 8-5

x Contents

Property Attributes ............................................ 8-6

Purpose of Property Attributes ................................. 8-6

Specifying Property Attributes ................................. 8-6

Table of Property Attributes ................................... 8-6

Property 'efinLtLon ........................................... 8-12

What You Can Define ....................................... 8-12

Initialize Property Values .................................... 8-12

Property Default Values ..................................... 8-13

Initializing Properties to Handle Objects ......................... 8-13

Assign Property Values in Constructor .......................... 8-14

Property Attributes ......................................... 8-15

Methods to Set and Get Property Values ......................... 8-15

Reference Object Properties Using Variables ..................... 8-16

Mutable and Immutable Properties .............................. 8-17

Set Access to Property Values ................................. 8-17

Define Immutable Property ................................... 8-17

Validate Property Values ....................................... 8-19

Property Validation in Class Definitions ......................... 8-19

Sample Class Using Property Validation ......................... 8-20

Order of Validation ......................................... 8-21

Abstract Property Validation .................................. 8-22

Objects Not Updated When Changing Validation ................... 8-22

Validation During Load Operation .............................. 8-22

Property Class and Size Validation ............................... 8-24

Property Class and Size ..................................... 8-24

Property Size Validation ..................................... 8-24

Property Class Validation .................................... 8-25

Default Values Per Size and Class .............................. 8-29

Property Validation Functions .................................. 8-30

MATLAB Validation Functions ................................. 8-30

Validate Property Using Functions ............................. 8-32

Define Validation Functions .................................. 8-35

Add Support for Validation Functions ........................... 8-36

Metadata Interface to Property Validation ........................ 8-38

Property Access Methods ...................................... 8-40

Properties Provide Access to Class Data ......................... 8-40

Property Set and Get Methods ................................ 8-40

Set and Get Method Execution and Property Events ................ 8-42

Access Methods and Properties Containing Arrays ................. 8-43

Access Methods and Arrays of Objects .......................... 8-43

Modify Property Values with Access Methods ..................... 8-43

Property Set Methods ......................................... 8-45

Overview of Property Access Methods .......................... 8-45

Property Set Method Syntax .................................. 8-45

Validate Property Set Value ................................... 8-45

When Set Method Is Called ................................... 8-46

xi

Property Get Methods ......................................... 8-48

Overview of Property Access Methods .......................... 8-48

Property Get Method Syntax .................................. 8-48

Calculate Value for Dependent Property ......................... 8-48

Errors Not Returned from Get Method .......................... 8-49

Get Method Behavior ....................................... 8-49

Set and Get Methods for Dependent Properties .................... 8-50

Calculate Dependent Property Value ............................ 8-51

When to Use Set Methods with Dependent Properties ............... 8-51

Private Set Access with Dependent Properties .................... 8-52

Properties Containing Objects .................................. 8-53

Assigning Objects as Default Property Values ..................... 8-53

Assigning to Read-Only Properties Containing Objects .............. 8-53

Assignment Behavior ....................................... 8-53

Dynamic Properties — Adding Properties to an Instance ............ 8-55

What Are Dynamic Properties ................................. 8-55

Define Dynamic Properties ................................... 8-55

List Object Dynamic Properties ................................ 8-57

Set and Get Methods for Dynamic Properties ...................... 8-59

Create Access Methods for Dynamic Properties ................... 8-59

Shared Set and Get Methods ................................. 8-60

Dynamic Property Events ...................................... 8-61

Dynamic Properties and Ordinary Property Events ................. 8-61

Dynamic-Property Events .................................... 8-61

Listen for a Specific Property Name ............................ 8-62

PropertyAdded Event Callback Execution ........................ 8-63

PropertyRemoved Event Callback Execution ...................... 8-63

How to Find meta.DynamicProperty Objects ...................... 8-63

Dynamic Properties and ConstructOnLoad ........................ 8-65

Methods — 'efinLnJ Class Operations

9

Methods in Class Design ........................................ 9-2

Class Methods ............................................. 9-2

Examples and Syntax ........................................ 9-2

Kinds of Methods ........................................... 9-2

Method Naming ............................................ 9-3

Method Attributes ............................................. 9-4

Purpose of Method Attributes .................................. 9-4

Specifying Method Attributes .................................. 9-4

Table of Method Attributes .................................... 9-4

Ordinary Methods ............................................. 9-6

Ordinary Methods Operate on Objects ........................... 9-6

xii Contents

Methods Inside classdef Block ................................. 9-6

Method Files .............................................. 9-7

Methods in Separate Files ...................................... 9-8

Class Folders .............................................. 9-8

Define Method in Function File ................................. 9-8

Specify Method Attributes in classdef File ........................ 9-9

Methods You Must Define in the classdef File ..................... 9-10

Method Invocation ............................................ 9-11

Determining Which Method Is Invoked .......................... 9-11

Referencing Names with Expressions—Dynamic Reference ........... 9-13

Index into Result of Method Call ............................... 9-14

Controlling Access to Methods ................................ 9-14

Invoking Superclass Methods in Subclass Methods ................. 9-15

Invoking Built-In Functions ................................... 9-15

Class Constructor Methods ..................................... 9-16

Purpose of Class Constructor Methods .......................... 9-16

Basic Structure of Constructor Methods ......................... 9-16

Guidelines for Constructors .................................. 9-17

Default Constructor ........................................ 9-18

When to Define Constructors ................................. 9-18

Related Information ........................................ 9-18

Initializing Objects in Constructor ............................. 9-18

No Input Argument Constructor Requirement ..................... 9-19

Subclass Constructors ...................................... 9-19

Implicit Call to Inherited Constructor ........................... 9-21

Errors During Class Construction .............................. 9-22

Output Object Suppressed ................................... 9-22

Static Methods ............................................... 9-24

What Are Static Methods .................................... 9-24

Why Define Static Methods ................................... 9-24

Defining Static Methods ..................................... 9-24

Calling Static Methods ...................................... 9-24

Inheriting Static Methods .................................... 9-25

Overload Functions in Class 'efinLtLons .......................... 9-26

Why Overload Functions ..................................... 9-26

Implementing Overloaded MATLAB Functions .................... 9-26

Rules for Naming to Avoid Conflicts ............................ 9-28

Class Support for Array-Creation Functions ....................... 9-29

Extend Array-Creation Functions for Your Class ................... 9-29

Which Syntax to Use ........................................ 9-30

Implement Support for Array-Creation Functions .................. 9-30

Object Precedence in Method Invocation ......................... 9-36

Object Precedence ......................................... 9-36

Defining Precedence ........................................ 9-36

Dominant Argument in Overloaded Graphics Functions ............. 9-38

Graphics Object Precedence .................................. 9-38

Dominant Argument ........................................ 9-38

xiii

Defining Class Precedence ................................... 9-38

Calls to Inferior-Class Methods ................................ 9-39

Class Methods for Graphics Callbacks ............................ 9-41

Referencing the Method ..................................... 9-41

Syntax for Method Callbacks ................................. 9-41

Use a Class Method for a Slider Callback ........................ 9-42

Object Arrays

10

Construct Object Arrays ....................................... 10-2

Build Arrays in the Constructor ............................... 10-2

Referencing Property Values in Object Arrays ..................... 10-2

Initialize Object Arrays ........................................ 10-5

Calls to Constructor ........................................ 10-5

Initial Value of Object Properties .............................. 10-6

Empty Arrays ................................................ 10-7

Creating Empty Arrays ...................................... 10-7

Assigning Values to an Empty Array ............................ 10-7

Initialize Arrays of Handle Objects .............................. 10-9

Related Information ....................................... 10-10

Accessing Dynamic Properties in Arrays ......................... 10-11

Implicit Class Conversion ..................................... 10-13

Class Conversion Mechanism ................................ 10-13

Concatenation ........................................... 10-13

Subscripted Assignment .................................... 10-13

Concatenating Objects of 'Lfferent Classes ...................... 10-15

Basic Knowledge ......................................... 10-15

MATLAB Concatenation Rules ............................... 10-15

Concatenating Objects ..................................... 10-15

Calling the Dominant-Class Constructor ........................ 10-16

Converter Methods ........................................ 10-17

Designing Heterogeneous Class Hierarchies ..................... 10-20

Creating Classes That Support Heterogeneous Arrays ............. 10-20

MATLAB Arrays .......................................... 10-20

Heterogeneous Hierarchies ................................. 10-20

Heterogeneous Arrays ..................................... 10-21

Heterogeneous Array Concepts .............................. 10-21

Nature of Heterogeneous Arrays ............................. 10-22

Unsupported Hierarchies ................................... 10-24

Default Object ........................................... 10-25

Conversion During Assignment and Concatenation ................ 10-26

Empty Arrays of Heterogeneous Abstract Classes ................. 10-26

xiv Contents

Heterogeneous Array Constructors ............................. 10-27

Building Arrays in Superclass Constructors ..................... 10-27

When Errors Can Occur .................................... 10-27

Initialize Array in Superclass Constructor ....................... 10-27

Sample Implementation .................................... 10-28

Potential Error ........................................... 10-30

Events — Sending and Responding to Messages

11

Overview Events and Listeners .................................. 11-2

Why Use Events and Listeners ................................ 11-2

Events and Listeners Basics .................................. 11-2

Event Syntax ............................................. 11-2

Create Listener ........................................... 11-3

'efine Custom Event Data ..................................... 11-5

Class Event Data Requirements ............................... 11-5

Define and Trigger Event .................................... 11-5

Define Event Data ......................................... 11-6

Create Listener for Overflow Event ............................. 11-6

Observe Changes to Property Values ............................. 11-8

Implement Property Set Listener ............................... 11-10

PushButton Class Design ................................... 11-10

Event and Listener Concepts .................................. 11-12

The Event Model ......................................... 11-12

Limitations .............................................. 11-12

Default Event Data ........................................ 11-13

Events Only in Handle Classes ............................... 11-13

Property-Set and Query Events ............................... 11-13

Listeners ............................................... 11-14

Event Attributes ............................................. 11-15

Specify Event Attributes .................................... 11-15

Events and Listeners Syntax ................................... 11-17

Components to Implement .................................. 11-17

Name Events ............................................ 11-17

Trigger Events ........................................... 11-17

Listen to Events .......................................... 11-18

Define Event-Specific Data .................................. 11-20

Listener Lifecycle ........................................... 11-22

Control Listener Lifecycle ................................... 11-22

Temporarily Deactivate Listeners ............................. 11-22

Permanently Delete Listeners ................................ 11-22

Listener Callback Syntax ..................................... 11-23

Specifying Listener Callbacks ................................ 11-23

xv

Tải ngay đi em, còn do dự, trời tối mất!