Check out our OOP Code Repository Files or visit the LabVIEW Wiki OOP Portal.
Tags |
(This content has not been tagged yet)
|
![]() |
Aug 25 2006, 10:39 PM
Post
#1
|
|||
![]() LV R&D Envoy NI ![]() Posts: 1226 Joined: 15-August 06 From: Austin, TX Member No.: 5877 Using LabVIEW Since:2000 LV:8.5.1 ,. ,.
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. 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
|
||
|
|
|||
| Ad |
Aug 25 2006, 10:39 PM
Post
#
|
||
|
|
|
||
|
|
|||
Aug 25 2006, 11:48 PM
Post
#2
|
|||
![]() I'm a LAVA, not a fighter. V I Engineering, Inc. ![]() Posts: 3759 Joined: 13-October 03 From: Michigan, USA Member No.: 181 Using LabVIEW Since:1993 LV:8.5 ,. ,.
My Blog
|
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 I also like (and agree with) the "whole new flavor of über-geek nirvana!" -------------------- ![]()
|
||
|
|
|||
Aug 26 2006, 09:44 AM
Post
#3
|
|||
|
Drawing Tool - LVOOP example application Premium Member ![]() Posts: 1169 Joined: 29-January 06 From: Helsinki Member No.: 4014 Using LabVIEW Since:2004 LV:8.5.1 ,8.2.1 ,7.1.1
My Blog
|
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
--------------------
|
||
|
|
|||
Aug 26 2006, 12:10 PM
Post
#4
|
|||
![]() LV R&D Envoy NI ![]() Posts: 1226 Joined: 15-August 06 From: Austin, TX Member No.: 5877 Using LabVIEW Since:2000 LV:8.5.1 ,. ,.
My Gallery
|
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
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
|
||
|
|
|||
Aug 26 2006, 10:25 PM
Post
#5
|
|||
|
Drawing Tool - LVOOP example application Premium Member ![]() Posts: 1169 Joined: 29-January 06 From: Helsinki Member No.: 4014 Using LabVIEW Since:2004 LV:8.5.1 ,8.2.1 ,7.1.1
My Blog
|
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. --------------------
|
||
|
|
|||
Sep 4 2006, 06:05 PM
Post
#6
|
|||
![]() LV R&D Envoy NI ![]() Posts: 1226 Joined: 15-August 06 From: Austin, TX Member No.: 5877 Using LabVIEW Since:2000 LV:8.5.1 ,. ,.
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: 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
|
||
|
|
|||
Sep 4 2006, 08:31 PM
Post
#7
|
|||
|
Drawing Tool - LVOOP example application Premium Member ![]() Posts: 1169 Joined: 29-January 06 From: Helsinki Member No.: 4014 Using LabVIEW Since:2004 LV:8.5.1 ,8.2.1 ,7.1.1
My Blog
|
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 --------------------
|
||
|
|
|||
Sep 5 2006, 05:25 AM
Post
#8
|
|||
![]() LV R&D Envoy NI ![]() Posts: 1226 Joined: 15-August 06 From: Austin, TX Member No.: 5877 Using LabVIEW Since:2000 LV:8.5.1 ,. ,.
My Gallery
|
Elegant 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
|
||
|
|
|||
Sep 5 2006, 09:22 AM
Post
#9
|
|||
|
Drawing Tool - LVOOP example application Premium Member ![]() Posts: 1169 Joined: 29-January 06 From: Helsinki Member No.: 4014 Using LabVIEW Since:2004 LV:8.5.1 ,8.2.1 ,7.1.1
My Blog
|
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 Edit: Some more brain work.... your design pattern would also allow users to make pure virtual classes This post has been edited by jimi: Sep 5 2006, 09:41 AM --------------------
|
||
|
|
|||
Sep 5 2006, 02:57 PM
Post
#10
|
|||
![]() LV R&D Envoy NI ![]() Posts: 1226 Joined: 15-August 06 From: Austin, TX Member No.: 5877 Using LabVIEW Since:2000 LV:8.5.1 ,. ,.
My Gallery
|
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 Worth thinking about, certainly. At this point I don't see any pitfalls. Edit: Some more brain work.... your design pattern would also allow users to make pure virtual classes 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
|
||
|
|
|||
Sep 5 2006, 03:16 PM
Post
#11
|
|||
|
Drawing Tool - LVOOP example application Premium Member ![]() Posts: 1169 Joined: 29-January 06 From: Helsinki Member No.: 4014 Using LabVIEW Since:2004 LV:8.5.1 ,8.2.1 ,7.1.1
My Blog
|
My brain is going slow this morning. How does this work? I was wrong, you cannot 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. --------------------
|
||
|
|
|||