Object-Oriented Programming (OOP) is a programming paradigm that enforces object-oriented design principles to solve software problems. In object-oriented programming, a class defines data and methods to work with that data. A client then creates an object - a specific instance of a class - to perform actions using methods that are exposed by the class. Implementation details are hidden from the client.
Because implementation details are hidden from the client, methods and data of a class can change without affecting any of the client's code. This can even happen at runtime by replacing one class with another of the same kind. Classes can inherit methods and data from a parent class to override methods of the parent class. The client can then use the child class as if it was the parent class, without changing any of the existing code. Methods called by the client will seamlessly execute the methods defined by the child class. If the child class doesn't override a method, the parent's method is called. This behavior is called dynamic dispatching in LabVIEW.
Object-Oriented Programming in LabVIEW
A class is defined by a class library that serves as a user-defined data type. Each class consists of a private data control and methods (member VIs) to access that data. A class can change the access scope of its methods to public (anyone), protected (this class and its descendants), community (this class and its friends) or private (this class).
An object is a specific instance of a class. It is represented by data on a wire and behaves like a cluster. Objects in G are by-value. When a wire forks, the object may be duplicated, as decided by the LabVIEW compiler. A wire of a specific class can carry an object of that class or any of its descendants without loss of data.
G supports single inheritance in which a class can have only one parent. Children inherit public and protected methods from their parent and can override inherited dynamic dispatch methods. A parent class can require a descendant to override specific dynamic dispatch methods and to call the parent method from inside the override.
Many common object-oriented design patterns have been adapted into the by-value dataflow in G.
- Aggregation pattern
- Command pattern
- Decorator pattern (aka. Wrapper pattern)
- Delegation (aka. Delegation pattern)
- Factory pattern
- Hierarchy composition pattern
- Singleton pattern
- Specification pattern
- Strategy pattern (aka. Policy pattern)
- Template method pattern (aka. Channeling pattern)
- Visitor pattern
See also: Category:Object-Oriented Design Patterns
Benefits of OOP
- LabVIEW Class
- LabVIEW Object
- LabVIEW object-oriented programming FAQ
- Americas CLA Summit 2019: G Interfaces by Stephen Loftus-Mercer
- Graphical Object-Oriented Programming (GOOP)
- G# Framework
- LabVIEW Object-Oriented Programming FAQ by National Instruments
- LabVIEW Object-Oriented Programming: The Decisions Behind the Design by National Instruments
- Code Reuse through Classes by Christina Rogers
- Introduction to Object Oriented Programming by Elijah Kerry
- When should you use classes by Elijah Kerry
|This article is a stub. You can help LabVIEW Wiki by expanding it.
Please improve this article if you can.