Popular Post MikaelH Posted July 28, 2009 Popular Post Report Share Posted July 28, 2009 Interface The concept interface doesn’t exist in LabVIEW yet, but I hope that it will be added in the future. An interface class is an abstract class that only contains empty methods/VIs. So when someone calls this method/VI the call should be forward to the real implementation of this method in the class that implements this interface, just like normal inheritance, but instead of deriving for this Interface class the OO term is to implement this interface. Many design patterns uses the Interface concept e.g. Command Pattern and Observer. So how do you implement an interface in LabVIEW? Of cause you can make your classes all inherit from the Interface class they need to use. But is really a UUT a kind of command? Is a Player a kind of Observer? You should always be able to say the <child class> is a type of <parent class> E.g. A car is a type of vehicle. But maybe you can ignore this rule for those classes, but maybe you want to implement several interfaces, then you’d run into trouble. The way I implement this in LabVIEW is by using an Interface Helper class. So if I have this example where 2 different classes like to implement MyInterface. I have to create an extra Interface child class to the Interface parent class, so I can make use of the powerful dynamic dispatch. These are two very small classes only containing the methods defined by the interface. So when someone calls the Update method/VI in the Interface class, that call will be directed to the Update methods in my X_MyInterafce class which only forwards the call to the Update method in the Player or Spectator class. This way I can implement several interfaces. I’ve made a small example code that uses this approach together with the observer design pattern ( PartII). Project: TennisGame.zip You need some Class VIs you get when installing GDS Key: COMM-UNIT-YEDI-TION-2009 The main VI does these things: Creates the TennisBall, 2 Players, X no of Spectators Creates the Help classes PlayerInterface and SpectatorInterface These 2 help classes are used as inputs to the Ball:AttachObserver method. The AttachObserver method stores the reference to all observers/subscribers The main VI updates the Ball's position using the SetBallPosition method. This method sets the new positions and also calls the NotifyObserver method. The NotifyObserver calls the update method on all Observers that are attached. The Update method in the Player and Spectator class, has now been informed that the tennis ball has been moved and they update their private attribute they have of the balls position. This might not the best way of implementing this problem, but shows how the players and spectators can be notified when something they have subscribed to happens. Cheers, Mikael 3 Quote Link to comment
Daklu Posted July 29, 2009 Report Share Posted July 29, 2009 Your design sounds very similar to something I posted a couple months ago on Lava 1.0. (Link - The downloads aren't available anymore but I might be able to drum them up if you're really interested.) I'll have to download your code this weekend and study it, but it's nice to see others are trying to figure out how to work around not having native interfaces. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.