Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 5 Sequences & Scripting > 5.20 Object Oriented Programming

5.20.2 Classes as Structures

Scroll Prev Top Next More

At the basic level, an object is just a structure, meaning a collection of member variables.  This is useful for storing groups of data.  For example, you could create an object to store a person's name and address.  But, in general, you first have to define the class:

 

class Person

  local string name

  local string address

  local string zip

endclass

A class on its own does nothing but define the structure.  To be able to use it you must instantiate the class.  An instantiated class definition is called an object, and it is stored in a variable just like any number.  So, to create a variable to store a person's name and address after creating the above class definition you might do:

 

global Frank = new(Person)

The new() function instantiates the given class and returns an instance of it.  In this case we are storing the instance in the variable Frank.  Now we can set Frank's name and address member variables:

 

Frank.name = "Frank Smith"

Frank.address = "123 Main St"

Frank.zip = "12345"

Notice how we use the dot notation similar to many of the system variables and functions to access the member variables of our object.