ts2060 introduction to object-oriented programming in ni labview (1)
DESCRIPTION
labview objectTRANSCRIPT
![Page 1: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/1.jpg)
Introduction to LabVIEW
Object-Oriented Programming
Adam Kemp
LabVIEW R&D
![Page 2: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/2.jpg)
Agenda
•Object-oriented concepts
•Object-oriented programming in LabVIEW
•Example use of Object-oriented programming
![Page 3: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/3.jpg)
Coupling and Cohesion
•Two useful measures for how modular, reusable,
and extensible your application is
•Coupling: How much separate components or •Coupling: How much separate components or
pieces of code depend on one another
•Cohesion: How closely the functions or features
within a component are related
![Page 4: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/4.jpg)
Coupling
•High coupling means changing code in one piece
of code causes you to have to modify another
piece of code
•Low coupling means you can safely change code •Low coupling means you can safely change code
without affecting other code
•Low coupling is good
![Page 5: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/5.jpg)
Cohesion
•Low cohesion means modules are poorly
defined and contain functionality which
does not belongdoes not belong
•High cohesion means each module has a
well defined function and all code within it
goes together
•High cohesion is good
![Page 6: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/6.jpg)
Benefits of OOP
•Object Oriented Programming tends to:
–Produce code which is easier to write.
–Produce code which is easier to debug.–Produce code which is easier to debug.
–Produce code which will be easier to maintain.
–Lower coupling
–Higher cohesion
![Page 7: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/7.jpg)
What Is Object-Oriented Design?
Task-Oriented design Object-Oriented design
•Step-by-step instructions
•Sequence of tasks
•Areas of Responsibility
•Set of Objects•Sequence of tasks •Set of Objects
![Page 8: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/8.jpg)
Two Descriptions of the Same Problem
•We want to test each board at the end of an
assembly line to make sure each is functional.
We want to send an e-mail to management for
any failed tests.
vs.
•We want the assembly line to produce boards.
Each board should test itself for functionality
and report any problem. The log should send an
e-mail to management for any failed tests.
![Page 9: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/9.jpg)
Two Descriptions of the Same Problem
•We want to test each board at the end of an
assembly line to make sure each is functional.
We want to send an e-mail to management for
any failed tests.
vs.
•We want the assembly line to produce boards.
Each board should test itself for functionality
and report any problem. The log should send an
e-mail to management for any failed tests.
![Page 10: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/10.jpg)
What Is Object-Oriented Programming?
•Object Oriented Design
– Use of Object-Oriented concepts
•Object Oriented Programming•Object Oriented Programming
– Use of an Object Oriented Programming Language
– Alerts when Object Oriented concepts are violated
– Features which support use of Object-Oriented concepts
![Page 11: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/11.jpg)
Key OOP Language Features
•Encapsulation
•Inheritance
•Dynamic Dispatching (aka “Polymorphism”)
![Page 12: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/12.jpg)
Common OOP Languages
•C++
•C#
•Java
•Objective C•Objective C
•Perl
•Python
•LabVIEW 8.20 and later
![Page 13: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/13.jpg)
Key Terms
•Class
•Object
•Method
![Page 14: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/14.jpg)
What is a class?
•A class is a type
•A class consists of:
– Data type
– List of actions that work with that data (“methods”)– List of actions that work with that data (“methods”)
![Page 15: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/15.jpg)
What is an object?
•An object is a value
•An object is a specific instance of a class
•There may be many objects (instances) of a given
classclass
![Page 16: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/16.jpg)
What is a method?
•A method is an action which can be performed
on an object
•Belongs to a class
•Uses the data in an object•Uses the data in an object
![Page 17: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/17.jpg)
Examples of classes
Class: Car Person
Data:
•Make
•Model
•Year
•First Name
•Last Name
•Date of BirthData: •Year
•Mileage
•Date of Birth
•Gender
Methods:
•Check Brakes
•Rotate Tires
•Change Oil
•Get Full Name
•Get Age
![Page 18: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/18.jpg)
Examples of objects
Class: Car Person
Object:
•1954 Ford Mustang
•2004 Honda Accord
•Adam Kemp
•Steven Harrison
![Page 19: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/19.jpg)
Review: Classes, objects, and methods
•A class is a type
•An object is a value
•A method is an action
![Page 20: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/20.jpg)
What Is an “Object” In LabVIEW?
•An object is like a cluster
– Composite of other data
![Page 21: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/21.jpg)
What Is an “Object” In LabVIEW?
•An object is like a cluster
– Composite of other data
– Uses bundle, unbundle
– Copies when the wire forks
![Page 22: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/22.jpg)
What Is an “Object” In LabVIEW?
•An object is like a cluster
– Composite of other data
– Uses bundle, unbundle
– Copies when the wire forks
•Plus more!•Plus more!
– Custom Wire Appearance
![Page 23: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/23.jpg)
•An object is like a cluster
– Composite of other data
– Uses bundle, unbundle
– Copies when the wire forks
•Plus more!
What Is an “Object” In LabVIEW?
•Plus more!
– Custom Wire Appearance
– Functions to help use internal data
•The data type of an object is called its “class”
![Page 24: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/24.jpg)
What Is a “LabVIEW Class”?
•A user-defined data type
•A special type of library
![Page 25: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/25.jpg)
Anatomy of a LabVIEW Class
•Each LabVIEW class consists of:
– A data control (cluster)
– Member VIs to access that data
•Class file (.lvclass) stores class information
– Data control definition
– List of member VIs
– Properties of member VI
– Properties of the class itself (such as wire appearance)
![Page 26: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/26.jpg)
Object versus class in LabVIEW
•An object is a specific instance of a class
•An object is data on the wire
![Page 27: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/27.jpg)
Demo: Creating a New LabVIEW Class
![Page 28: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/28.jpg)
What Is Encapsulation?
Two related concepts:
1. Consolidation of data and methods into an
object
2. Hiding implementation details2. Hiding implementation details
![Page 29: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/29.jpg)
What Is Encapsulation?
Consolidation of data and methods into an object:
![Page 30: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/30.jpg)
What Is Encapsulation?
Hiding implementation details:
Accessor methods
![Page 31: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/31.jpg)
What Is Encapsulation?
![Page 32: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/32.jpg)
What Is Encapsulation?
![Page 33: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/33.jpg)
What Is Encapsulation?
![Page 34: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/34.jpg)
What Is Encapsulation?
![Page 35: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/35.jpg)
What Is Encapsulation?
![Page 36: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/36.jpg)
What Is Encapsulation?
![Page 37: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/37.jpg)
What Is Encapsulation?
Consolidation of data and methods into an object,
with restricted access to data
– Hides how an object works
– Easy to change data format
– Easier debugging– Easier debugging
– Hard to enforce without
language support
![Page 38: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/38.jpg)
Encapsulation in LabVIEW
LabVIEW classes specify scope of contents:
– Public: Accessible by any VI
– Private: Only accessible by VIs within the same class
– Protected: Accessible by VIs in the same class and
descendants (more later)descendants (more later)
– Community: Accessible by “friends” (advanced use case)
![Page 39: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/39.jpg)
Encapsulation in LabVIEW
LabVIEW classes specify scope of contents:
– Public: Accessible by any VI
– Private: Only accessible by VIs within the same class
![Page 40: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/40.jpg)
Encapsulation in LabVIEW
LabVIEW classes specify scope of contents:
– Public: Accessible by any VI
– Private: Only accessible by VIs within the same class
Top-Level VI(outside class)
Public Method A
Private Method A
Private Method B
Public Method B
Private Method C
Private Method D
![Page 41: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/41.jpg)
Encapsulation in LabVIEW
LabVIEW classes specify scope of contents:
– Public: Accessible by any VI
– Private: Only accessible by VIs within the same class
Top-Level VI(outside class)
Public Method A
Private Method A
Private Method B
Public Method B
Private Method C
Private Method D
![Page 42: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/42.jpg)
Benefits of Encapsulation
•Encapsulated code is easier to write.
– Each component using data can use the most convenient
form of that data.
•Encapsulated code is more stable.
– Less code must change when data format changes.– Less code must change when data format changes.
•Encapsulated code is easier to maintain.
–Less code must change to introduce features and fix bugs.
•Lower coupling
![Page 43: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/43.jpg)
Demo: Encapsulation in LabVIEW
![Page 44: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/44.jpg)
What Is Inheritance?
Human Class Feline Class•Get Age
•Get Gender
•Drive Car
•Get Age
•Get Gender
•Meow
![Page 45: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/45.jpg)
What Is Inheritance?
•Get Age
•Get GenderMammal Class
Human Class Feline Class•Get Age
•Get Gender
•Drive Car
•Get Age
•Get Gender
•Meow
![Page 46: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/46.jpg)
What Is Inheritance?
•Get Age
•Get GenderMammal Class
(parent)Inheritance
A feline is a
type of mammal.
A human is a
type of mammal.
Human Class
(child)
Feline Class
(child)
•Get Age
•Get Gender
•Drive Car
•Get Age
•Get Gender
•Meow
![Page 47: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/47.jpg)
Inheritance Example
Ancestors
Descendants
Mammal
Human Feline
Big Feline
Lion Tiger
Housecat
![Page 48: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/48.jpg)
Inheritance Example
Ancestors
Descendents
Mammal
Human Feline
Big Feline
Lion Tiger
Housecat
– Protected: only accessed by class and its descendants
![Page 49: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/49.jpg)
Inheritance and wire types
- A wire of some class type can carry an object of
that class or any of the class’s descendants
- No data lost when this is done.
![Page 50: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/50.jpg)
To More Specific/Generic Class
Used to cast an object to another class
No data lost
Will return
an error at
run time
![Page 51: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/51.jpg)
Inheritance in LabVIEW
•Public Inheritance
•Single Inheritance
•Library Properties Dialog•Library Properties Dialog
![Page 52: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/52.jpg)
Inheritance in LabVIEW
![Page 53: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/53.jpg)
Benefits of Inheritance
•Inherited code is easier to write.
– Child classes are already partially written (code reuse).
•Inherited code is more stable.
– Child classes can be built on proven foundations.
•Inherited code is easier to maintain.•Inherited code is easier to maintain.
– Reduced duplicate code by providing common methods in
a common parent.
•Higher cohesion
![Page 54: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/54.jpg)
Demo: Inheritance in LabVIEW
![Page 55: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/55.jpg)
Static vs. Dynamic Dispatching
•Static method – Defined by single VI throughout
the class inheritance hierarchy.
•Dynamic method – Defined by multiple VIs with •Dynamic method – Defined by multiple VIs with
the same name throughout the class hierarchy.
– Child classes override the method defined in the parent.
– Parent defines a contract
– Children fulfill the contract
![Page 56: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/56.jpg)
Dynamic Dispatch
Mammal
Human Feline
*
Big Feline
Lion Tiger
Housecat
![Page 57: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/57.jpg)
Dynamic Dispatching
– Wire value at runtime determines which VI to call
– Code written against a set of promises made by parent.
![Page 58: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/58.jpg)
Dynamic Dispatching
– Wire value at runtime determines which VI to call
– Code written against a set of promises made by parent.
![Page 59: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/59.jpg)
Dynamic Dispatching
What makes a dynamic dispatch VI?
– Inside a class
Mammal
![Page 60: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/60.jpg)
Dynamic Dispatching
What makes a dynamic dispatch VI?
– Inside a class
– Inheritance hierarchy
– Same NameMammal
Human
![Page 61: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/61.jpg)
Dynamic Dispatching
What makes a dynamic dispatch VI?
– Inside a class
– Inheritance hierarchy
– Same Name
– Same connector pane
Mammal
– Same connector pane
– Dynamic Dispatch TerminalHuman
![Page 62: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/62.jpg)
Call Parent Node
Used on child VI to invoke the parent VI
![Page 63: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/63.jpg)
Benefits of Dynamic Dispatch
•Dynamically dispatched code is easier to write.
– Write code against the interface provided by the parent,
which then works with any child supporting that interface.
•Dynamically dispatched code is easier to maintain.
– New child classes can often be inserted into existing – New child classes can often be inserted into existing
frameworks without modifying the framework.
•Lowers coupling
![Page 64: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/64.jpg)
Demo: Dynamic Dispatching
![Page 65: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/65.jpg)
Example: Circuit Board Test
•Scenario
– LabVIEW-based circuit board test system
•Requirements
– Different types of boards must be tested– Different types of boards must be tested
– New types of boards will be added in the future
•Goals
– Maximize code reuse and system scalability
![Page 66: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/66.jpg)
Demo: Board Test System
![Page 67: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/67.jpg)
Additional Resources
• White papers on ni.com
• Webcast on ni.com
• Example Finder
• Other sessions:
– “Trends in NI LabVIEW Object-Oriented Programming”
– Tuesday 3:30 in 13 A/B (next session right here)
– “Practical Examples of NI LabVIEW Object-Oriented Programming
Classes and Use Cases”
– Tuesday 4:45 in 10C
![Page 68: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/68.jpg)
Questions?
![Page 69: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/69.jpg)
LabVIEW OOP Compared With C++
Q: How do LabVIEW classes compare with C++?
A: Some (but not all) of the differences include:
– C++ has constructors and destructors; LabVIEW has no – C++ has constructors and destructors; LabVIEW has no
need for them.
![Page 70: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/70.jpg)
LabVIEW OOP Compared With C++
Q: How do LabVIEW classes compare with C/C++?
A: Some (but not all) of the differences include:
– C++ has constructors and destructors; LabVIEW has no – C++ has constructors and destructors; LabVIEW has no
need for them.
– C++ has function overloading (LabVIEW does not).
– C++ has multiple inheritance (LabVIEW does not).
![Page 71: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/71.jpg)
By-Value vs. By-Reference
Q: Why do LabVIEW classes use a by-value model
instead of by-reference model?
A: By-value model is a better fit for LabVIEW.
Examples:
– Maintains LabVIEW’s dataflow programming style.
– Avoids race conditions
– Reduces developer burden
– LabVIEW 2009: Data Value References
*”What's New in LabVIEW Object Oriented Programming”
*
![Page 72: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/72.jpg)
Operating System and Target Support
Q: Which OSes do LabVIEW classes support?
Real-Time*Windows
Mobile / Touch Panel*
FPGA*
Macintosh
Linux
* LabVIEW 2009
![Page 73: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/73.jpg)
Dynamic Dispatching Overhead
Q: Does Dynamic Dispatching have a runtime cost?
• A little (constant, regardless of override count)
• Almost certainly less than alternatives• Almost certainly less than alternatives
![Page 74: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/74.jpg)
Dynamic Dispatching Overhead
Q: Does Dynamic Dispatching have a runtime cost?
• A little (constant, regardless of override count)
• Almost certainly less than alternatives• Almost certainly less than alternatives
• Wire Parent’s VI as you would Descendants
![Page 75: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/75.jpg)
Migrating to LabVIEW Classes
Q: How can I update an existing LabVIEW program
to use classes?
![Page 76: TS2060 Introduction to Object-Oriented Programming in NI LabVIEW (1)](https://reader033.vdocument.in/reader033/viewer/2022052212/545eb5a3b1af9ffa588b48c1/html5/thumbnails/76.jpg)
Migrating to LabVIEW Classes
Q: How can I update an existing LabVIEW program
to use classes?