LAVA Forums Buy cool LAVA gear Forums RSS Feed

Welcome Guest ( Log In | Register )

Tags
This content has not been tagged yet

> Related links

Check out our OOP Code Repository Files or visit the LabVIEW Wiki OOP Portal.


2 Pages V   1 2 >  
Reply to this topic Start new topic
> LabVOOP Design Patterns, v1.0
Aristos Queue
post Aug 25 2006, 10:39 PM
Post #1


LV R&D Envoy
*****

NI
Posts: 1188
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


I've posted a document on my personal website on the topic of LabVOOP Design Patterns.

Here's a bit from the introduction to let you decide whether you want to dive into the whole document. book.gif Feedback is welcome. Eventually I'd like to put this up on DevZone, after it has a bit of polish, but it has not been reviewed by any tech writers yet.

When talking about computer programming, a design pattern is a standard correct way to organize your code. When trying to achieve some particular result, you look to the standard design patterns first to see if a solution already exists. This sounds a lot like an algorithm. An algorithm is a specific sequence of steps to take to calculate some result from a set of data. Generally algorithms can be written once in any given programming language and then reused over and over again. Design patterns are rewritten over and over again. For example, in house cleaning, consider this algorithm for vacuuming a carpet: "Start in one corner, walk horizontally across the floor, then move to the side and continue making adjacent parallel stripes until the whole floor is vacuumed." Compare this with the design pattern for cleaning a room: "Start cleaning at the ceiling and generally work your way down so that dirt and dust from above settle on the still unclean areas below." Design patterns are less specific than algorithms. You use the patterns as a starting point when writing the specific algorithm.

--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Ad
post Aug 25 2006, 10:39 PM
Post #















Tags
This content has not been tagged yet
Go to the top of the page
Quote Post
crelf
post Aug 25 2006, 11:48 PM
Post #2


I'm a LAVA, not a fighter.
******

V I Engineering, Inc.
Posts: 3635
Joined: 13-October 03
From: Michigan, USA
Member No.: 181
Using LabVIEW Since:1993
LV:8.5 ,. ,.
Australia United States Nothing Selected My Blog


QUOTE (Aristos Queue @ Aug 26 2006, 08:39 AM) *
I've posted a document on my personal website on the topic of LabVOOP Design Patterns.

Nicely done Stephen - thourough, and I especially appreciate your parallel to the gang of four patterns smile.gif This document should definately become part of the LabVIEW documentation in the future. Now it's our job to further define the patterns that you've listed, and maybe come up with new ones where appropriate...

I also like (and agree with) the "whole new flavor of über-geek nirvana!"

--------------------


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Tomi Maila
post Aug 26 2006, 09:44 AM
Post #3


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1159
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


QUOTE (Aristos Queue @ Aug 26 2006, 01:39 AM) *
I've posted a document on my personal website on the topic of LabVOOP Design Patterns.


I would greatly appreciate LabVOOP design patterns. However you Aristos mentioned in another post that LabVOOP that it's currently hard to know which is the best design since the language is so new. So I don't think that a fixed document can do the thing, LabVOOP design patterns will evolve for some time until we the community understand what is the best way to implement different things in this language. So instead of document I'd appreciate a kind of online design pattern library. Each design pattern should include
  • name of the pattern
  • verbal description of the pattern
  • UML of the class hierarchy
  • images clarifying the central parts of the code (png not jpg)
  • example code as a zip packages
  • discussion forum about the pros and cons of each design pattern in slashdot style, everybody can comment and suggest new design patterns but only the moderators can add new design patterns to keep the quality of patterns

--------------------
Tomi Maila



Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Aristos Queue
post Aug 26 2006, 12:10 PM
Post #4


LV R&D Envoy
*****

NI
Posts: 1188
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


QUOTE (jimi @ Aug 26 2006, 04:44 AM) *
I would greatly appreciate LabVOOP design patterns. However you Aristos mentioned in another post that LabVOOP that it's currently hard to know which is the best design since the language is so new. So I don't think that a fixed document can do the thing, LabVOOP design patterns will evolve for some time until we the community understand what is the best way to implement different things in this language. So instead of document I'd appreciate a kind of online design pattern library. Each design pattern should include
  • name of the pattern
  • verbal description of the pattern
  • UML of the class hierarchy
  • images clarifying the central parts of the code (png not jpg)
  • example code as a zip packages
  • discussion forum about the pros and cons of each design pattern in slashdot style, everybody can comment and suggest new design patterns but only the moderators can add new design patterns to keep the quality of patterns

The PDF is what you just asked for -- name, verbal description, image, link to example code, editorial comments. it's the best I've been able to pull together thus far. The patterns I've included are reasonably sound concept wise for LV... its the implementations that are questionable. The UML component, for example, will be hard to stabilize for some time, thus I didn't even attempt it in this draft. If you're looking for discussion about each individual pattern, I didn't think it was worth, at this point, starting a separate discussion forum for each one. You can do so if you think it's worth it.

--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Tomi Maila
post Aug 26 2006, 10:25 PM
Post #5


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1159
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


QUOTE (Aristos Queue @ Aug 26 2006, 03:10 PM) *
The UML component, for example, will be hard to stabilize for some time, thus I didn't even attempt it in this draft.

UML is very fast to comprehend where as reading pages of text is slow and still you may miss the point. I think UML would be even more important than the text. Drawing the most important classes and their relation is not a big task. If you use something like MS Visio to draw the UML and include these drawings in a word document, you can update the drawings in a few seconds if you change the class structure of the pattern. I think UML is a must for design patterns.

--------------------
Tomi Maila



Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Aristos Queue
post Sep 4 2006, 06:05 PM
Post #6


LV R&D Envoy
*****

NI
Posts: 1188
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


I finally had time to rewrite the Singleton Pattern for LabVOOP.
http://jabberwocky.outriangle.org/SingletonPattern.zip

Here is the accompanying text:


Singleton Pattern
(adapted from Gang of Four’s Singleton pattern)

Intent
Guarantee that a given class has only a single instance in memory, that no second instance can ever be created, and that all method calls refer to this single instance.

Motivation
When you create a class, sometimes it is advantageous to guarantee that a program always refers to the same global instance of the class. Perhaps the class represents a database. It would be unfortunate if some section of code accidentally instantiated its own database and thus failed to update the global database. Creating a global means all VIs can access the data. But it does not mean that all VIs will access the global. This pattern describes a framework of classes that guarantee that single instance of data.

Implementation
See
http://jabberwocky.outriangle.org/SingletonPattern.zip

(An example of this pattern shipped with LV8.2, but that example is flawed, a problem I did not realize before we released: \examples\lvoop\SingletonPattern\Design Pattern.lvproj )

In this implementation, we seek to guarantee a single instance of Data.lvclass. We achieve this by putting Data.lvclass into an owning library, Singleton.lvlib, and making the class private. Now no VI outside the class can ever drop the class as a control, constant or indicator, so we guarantee that all operations are limited to this library. Callers can use Singleton.lvlib:Checkout.vi to get the current value of the data, modify it using any of the operations defined by Singleton.lvlib and then set the new value with Singleton.lvlib:Checkin.vi. The public functions are the same functions that would normally be on the class itself. They are moved to the library so that the functionality is exposed without allowing the class itself to be dropped. Checkin.vi and Checkout.vi use a single-element queue to guarantee only one copy in memory at a time. While the element is checked out to be modified by some routine, no other operation can proceed, thus guaranteeing serial access to the data.


Editorial Comments
I do not like the implementation that shipped with LV8.2. In the time since LV8.2 released, I have found better ideas. This “post-release discovery” is one reason why more design patterns are not included with the shipping product. LabVOOP is too new, and many of the patterns identified during development may be found faulty when exposed to a wider audience (i.e. real customers). So I'm making this revision available.

The only hole in the above solution that I can find is VI Server. VI Server could get a reference to the Front Panel controls of Singleton’s member VIs and use the Value property to effectively manipulate a different instance of the class than the one in the queue. Would using Subroutine Priority prevent VI Server access? I think so, but that seems like a pretty odd way to fix these VIs. The fix may not be that necessary – I doubt that many people are going to attempt such a hack on the class. Anyone trying it is already aware that they’re working against the design of the class and may break components that depend upon the singleton nature.


--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Tomi Maila
post Sep 4 2006, 08:31 PM
Post #7


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1159
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


QUOTE (Aristos Queue @ Sep 4 2006, 09:05 PM) *
In this implementation, we seek to guarantee a single instance of Data.lvclass. We achieve this by putting Data.lvclass into an owning library, Singleton.lvlib, and making the class private. Now no VI outside the class can ever drop the class as a control, constant or indicator, so we guarantee that all operations are limited to this library.


Elegant smile.gif This way I think I can also force the use of class constructors.

--------------------
Tomi Maila



Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Aristos Queue
post Sep 5 2006, 05:25 AM
Post #8


LV R&D Envoy
*****

NI
Posts: 1188
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


QUOTE (jimi @ Sep 4 2006, 03:31 PM) *
Elegant smile.gif This way I think I can also force the use of class constructors.

I hadn't thought of it that way, but you're right. By embedding an Initializer in the place where we setup the queue. Then there's no way to get one of these values that hasn't been through the initialization function.

--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Tomi Maila
post Sep 5 2006, 09:22 AM
Post #9


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1159
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


QUOTE (Aristos Queue @ Sep 4 2006, 09:05 PM) *
I finally had time to rewrite the Singleton Pattern for LabVOOP.

After some more chaotic brain activity.... this pattern works. It's however somewhat more complicated to develop than a regular class and some limitations arises from the fact that public class methods need to be outside the class. So I have a suggestion for the future releases of LabVIEW which would make this pattern simpler.

The trick is that if user could define the access scope of the class constant/control, then the user could force the class to be initiated trough the class "constructor" and the singleton pattern would be easy to implement without any external library embedding. This addition would also make it possible for the class user to force constructor calls when needed.

A user could place private controls on front panel, but the VI wouldn't run if the control wasn't connected to an external buffer source (i.e. if the VI wouldn't called as a subVI). The user could also place private constants on block diagram. These constants wouldn't initiate a buffer but would only carry type information. A wire leaving from these constants could only be conntected to new kind of node terminals called "Type specifier" terminal. All sorts of typecast and unflatten functions would have this new terminal instead of the present "required" terminals. User could also define front panel terminals to be of "Type specifier" type, but then these terminals could only be conntected to other "Type specifier" terminals.

Aristos, do you think you could implement this in a future release of LV. After all it seems to me quite powerful addition to the language smile.gif

Edit: Some more brain work.... your design pattern would also allow users to make pure virtual classes smile.gif

This post has been edited by jimi: Sep 5 2006, 09:41 AM

--------------------
Tomi Maila



Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Aristos Queue
post Sep 5 2006, 02:57 PM
Post #10


LV R&D Envoy
*****

NI
Posts: 1188
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


QUOTE (jimi @ Sep 5 2006, 04:22 AM) *
Aristos, do you think you could implement this in a future release of LV. After all it seems to me quite powerful addition to the language smile.gif

Worth thinking about, certainly. At this point I don't see any pitfalls.

QUOTE (jimi @ Sep 5 2006, 04:22 AM) *
Edit: Some more brain work.... your design pattern would also allow users to make pure virtual classes smile.gif

My brain is going slow this morning. How does this work?

Oh, and I did find one hole in the entire solution... uninitialized shift registers. An unscrupulous programmer can connect the terminal output of one of the exposed VIs to the inside terminal of the right-hand shift register. Then the left-hand shift register, if left unwired, would be able to produce an uninitialized (in the most terribly litteral sense!) value of the class. To really enforce the pattern, I would need to force shift-registers to be wired if they cannot access the class.

--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Tomi Maila
post Sep 5 2006, 03:16 PM
Post #11


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1159
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


QUOTE (Aristos Queue @ Sep 5 2006, 05:57 PM) *
My brain is going slow this morning. How does this work?


I was wrong, you cannot smile.gif

QUOTE (Aristos Queue @ Sep 5 2006, 05:57 PM) *
Oh, and I did find one hole in the entire solution... uninitialized shift registers. An unscrupulous programmer can connect the terminal output of one of the exposed VIs to the inside terminal of the right-hand shift register. Then the left-hand shift register, if left unwired, would be able to produce an uninitialized (in the most terribly litteral sense!) value of the class. To really enforce the pattern, I would need to force shift-registers to be wired if they cannot access the class.


I think uninitialized shift registers and all other VI properties with state cause quite a lot of trouble since they don't really fit into a pure dataflow ideology. I'd like to see a possibility to have stateless VIs which could be used to implement real recursion.

--------------------
Tomi Maila



Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
bsvingen
post Sep 5 2006, 03:39 PM
Post #12


Very Active
***

Member
Posts: 162
Joined: 28-April 06
Member No.: 4885
Using LabVIEW Since:1994
LV:8.0.1 ,8.20 ,7.1.1
Norway nor_north_trondelag Nothing Selected


Well, whatever you decide doing please don't change anything in LabVIEW simply because it does not fit into a puristic idiology of some programming concept and/or have side effects that may be "misused" (whatever that is supposed to mean).

Shift registers (initialized or not) and LV2 style globals is probably the single most important reason why it is possible to do anything in LabVIEW besides passing data linearly down a wire from A to B via function Z(A). In the end it all boils down to getting real world results (on all levels).


Tags
This content has not been tagged yet
Go to the top of the page
+Quote Post
Aristos Queue
post Sep 5 2006, 04:43 PM
Post #13


LV R&D Envoy
*****

NI
Posts: 1188
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.5.1 ,. ,.
United States Nothing Selected Nothing Selected My Gallery


QUOTE (jimi @ Sep 5 2006, 10:16 AM) *
I was wrong, you cannot smile.gif
I think uninitialized shift registers and all other VI properties with state cause quite a lot of trouble since they don't really fit into a pure dataflow ideology. I'd like to see a possibility to have stateless VIs which could be used to implement real recursion.

Ah, stateless VIs. I'll add your voice to the chorus. I'd love to have that, too. ;-)

QUOTE (bsvingen @ Sep 5 2006, 10:39 AM) *
Well, whatever you decide doing please don't change anything in LabVIEW simply because it does not fit into a puristic idiology of some programming concept and/or have side effects that may be "misused" (whatever that is supposed to mean).

Don't worry. ;-) This wouldn't affect all VIs. The idea would be a VI th