Tuesday, October 21, 2008

Presentation on LabVIEW Object Oriented Programming

Here is a copy of a presentation about GOOP (Graphical Object Oriented Programming) I made at a LabVIEW User Group meeting in Orange County, California, in 2004.


GOOP

Graphical Object Oriented Programming

Allen Weekley July 29, 2004


OOP Languages
•Object Oriented Programming is a design method, not a language

•Some languages have support for OOP built in

•OOP can be used in LabVIEW with the GOOP Inheritance Toolkit

•Toolkit was created by Endevo in Sweden and is distributed in USA by VI Engineering


Benefits and Goals of OOP

•Natural

•Reliable

•Reusable

•Maintainable

•Extendable

•Timely


Benefits and Goals of OOP

•Natural
–Instead of programming in terms of software constructs, you program using the terminology of your particular problem –You can model a problem at a functional level instead of an implementation level

•Reliable
–The modular nature of objects allows you to change one part of a program without affecting other parts
–You can easily test OOP classes as independent modules

•Reusable
–Modularity allows you to easily reuse code –Inheritance allows you to extend existing objects
–Polymorphism allows you to write generic code
–Natural terminology makes code easier to understand
–Improving the code within an object will benefit all code that calls the object
–Encapsulation keeps calling software from breaking because the interface does not have to change when the implementation changes

•Extendable
–Inheritance allows you to easily create new classes from existing classes

•Timely
–Natural software simplifies the design of complex systems
–Multiple programmers can easily work on the same project because each task can be a standalone object that can be developed and tested independently


OOP Paradigm

•OOP is “Real World” –The goal is to program in terms of the problem to be solved rather than the requirements of the software environment

•An object holds state and behavior

•OOP is a contract –Access to data is only through the object interface

•So, behavior goes along with data
–Methods :: behavior
–Attributes :: data

•Access to an object is only through the interface –A method accesses attributes


Object Interface

•What is an interface in LabVIEW?
–Attributes are a cluster –Methods are VI’s

•Access is only through methods –In LabVIEW a method is a VI

•There are both public and private VI’s
–The contract is that a user of an object uses only public VI’s
–Private VI’s are to be used only within the object


Class

•A class is the design of an object

•A class defines the attributes and behaviors shared by a type of object

•A class is like a template or cookie cutter


GOOP Classes and Objects

•In GOOP
–A class is a group of VI’s on disk
–An object is the dynamically created references and data space

Object

•An object is created by instantiating a class
–In LabVIEW a “Create” VI is run that produces a unique refnum
–The reference is typed for the class
–Connecting to VI’s of any other class will produce an error at design time (the “broken arrow”)
–Each instance has its own set of data (a copy of the “attributes” with values unique to the instance)

•The using program can create multiple instances, each with its own data space, without any special programming


Class and Object Example

•A system may use two HP34401 DMM’s, say serial number 5683 and serial number 5798

•Two instances of the HP34401 object would be created from the HP34401 class

•If you ask each object for the serial number, one object would return SN 5683 and the other object would return SN 5798

Using GOOP Objects

•The paradigm is similar to file I/O functions
–File: Open – write data – close
–Object: Create reference– execute method – destroy reference


Object Oriented Concepts

•Encapsulation

•Inheritance

•Poymorphism


Encapsulation

•Data is isolated within the object

•Access from outside the object is only through a defined interface

•The implementation of the object can be changed without affecting the code that uses it, as long as the interface is not changed


Inheritance

•An class can inherit methods from a base class

•Less programming is required because code is reused


Polymorphism

•Methods can be redefined in subclasses and dynamically bound at runtime –
A method in a base class that is called by sub class reference will first check to see if a sub class method exists and run it; if not it will run the base class method

•Code is easily extended because you only have to write new methods for the things that are specific to the subclass; the rest of the base class can be used without alterations

When To Use GOOP

•Use GOOP for
–Large projects
–Multiple developers
–Projects that you know will have many changes


Object Oriented Design

•UML – Unified Modeling Language
•Less formal design methods


More Information

•Endevo – Developers of GOOP Toolkit
–www.endevo.se

•VI Engineering – US Distributor of GOOP Toolkit
–www.viengineering.com

•Open Source GOOP Toolkit
–http://www.openg.org/tiki/tiki-index.php?page=OpenGOOP

•White Paper on GOOP Inheritance Toolkit
–http://www.endevo.se/default.asp?lang=eng

•GOOP Application Note
–AN143

•GOOP Tutorial
http://zone.ni.com/devzone/conceptd.nsf/2d17d611efb58b22862567a9006ffe76/5d7db42c91f392fc86256aae00463d78?OpenDocument