Table Of Contents

Classes and Object-Oriented Programming

Last Modified: January 12, 2018

Object-oriented programming in G Dataflow uses the concepts of class structure, encapsulation, and inheritance that are common in object-oriented languages, such as C++ and Java. Following object-oriented programming practices may not be necessary If you want to create a simple program with one or two VIs. However, using classes can improve the development of large and complex projects.

  • Class—A collection of fields and methods that can access and manipulate the values the fields contain. You must add class functionality to a G Type document before you can define the class fields and methods.
  • Field—A data attribute that can describe every individual instance of a class. Use the Data view of the class G Type document to define the fields of a class.
  • Method—A segment of code that can interact with the class data or use class data to perform an operation. Use the Member List of the class G Type document to define the methods of a class.
  • Class Object—An instance of a class with a specific set of data values for the fields the class G Type document defines. A class object also has access to every method on the Member List of the class G Type document.

You can think of cars on the road as an conceptual example of classes. Despite a wide variety of car manufacturers, you can use several generic data attributes, such as the number of doors on the car and current speed at which the car is traveling, to describe every car you see. Each car also has a set of common methods that enable it to function using the data attributes that define the car. When you accelerate, brake, or use a turn signal, the car implements a method to change the state of the car.

The encapsulation of these generic data attributes and methods into a single unit defines the car class. Each car on the road is an object of the car class with a specific set of data values and methods that the car can perform on its data.

Classes are a core component of object-oriented programming, the practice of creating a program in terms of the objects on the diagram that interact and perform methods instead of the procedures the program performs itself. Creating an object-oriented program involves two parts:

  • Object-Oriented Design—Planning the classes you need for your program, the methods each class will contain, and how the classes will interact before you begin writing code.
  • Object-Oriented Programming—Developing code in a programming language that allows the user to adhere to object-oriented principles.

Using classes to create an object-oriented program can provide the following benefits for your program.

  • Separating code into small, maintainable VIs prevents changes you make to one class method from causing errors in other class methods.
  • Defining the access to data and methods of a class can enable you to find the source of an error quickly.
  • Specifying inheritance relationships between classes enables you to use stable code in an existing class to create additional classes that handle more specific situations and functions.

Recently Viewed Topics