Jump to content


Photo
- - - - -

Can I easily see (at runtime) if a child has implemented an override for a certain parent method


  • Please log in to reply
6 replies to this topic

#1 Jeffrey Habets

Jeffrey Habets

    Very Active

  • Premium Member
  • 188 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1997

Posted 23 August 2010 - 10:09 AM

Hi,

I'll illustrate my question with my use-case. While implementing a variant of the command pattern I want to have commands that are optionally undoable.
For this the command will have an Execute method that is a must-override and an Undo method that can optionally be overriden.

23-8-2010 11-58-43.png

What I'm looking for is a way to check at runtime (from the parent) if the child on the wire has implemented the Undo method, without calling it ofcourse.
Just curious if this is possible.

I know my ways to work around this, e.g. have attribute Undoable in baseclass, or introduce a CommandUndoable class (which is a child of Command) to be inherited from by undoable commands.
---
Jeffrey
VIT

#2 MikaelH

MikaelH

    The 500 club

  • Premium Member
  • 575 posts
  • Location:Sydney
  • Version:LabVIEW 2012
  • Since:1996

Posted 24 August 2010 - 05:44 AM

Since you can find out the Child Class name in runtime and you know the VI it should override, you can always:
1) Try to open the VI Reference to the VI using a string: <ChildClass>.lvclass:Undo.vi, since it belongs to a class it will be in memory.
2) Open a reference to the class and get it's members and check if it's in the list.

...or am I missing something?
//Mikael
Posted Image

#3 Jeffrey Habets

Jeffrey Habets

    Very Active

  • Premium Member
  • 188 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1997

Posted 24 August 2010 - 07:09 AM

Seems the one who was missing something was me.. :frusty:

But no worries I've got a vacation coming up.. All should be well after that. :cool:

Thanks!
---
Jeffrey
VIT

#4 MikaelH

MikaelH

    The 500 club

  • Premium Member
  • 575 posts
  • Location:Sydney
  • Version:LabVIEW 2012
  • Since:1996

Posted 24 August 2010 - 10:50 AM

Have a nice holiday
I just got back from a long weekend of skiing.
It was awesome, and next week I'll go snokeling, that's life down under :-)
Posted Image

#5 Shaun Hayward

Shaun Hayward

    Very Active

  • Members
  • PipPipPip
  • 138 posts
  • Location:New York, NY, USA
  • Version:LabVIEW 2010
  • Since:2003

Posted 24 August 2010 - 01:40 PM

Another option you could use (that doesnt need opening references etc) is to have the parent class VI return an error code (ie a "method not implemented" error) - that way, any override VIs will execute normally, but any classes that do not provide this functionality will error in a known way that you can catch and handle appropriately, etc.



#6 Jeffrey Habets

Jeffrey Habets

    Very Active

  • Premium Member
  • 188 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1997

Posted 24 August 2010 - 08:20 PM

Another option you could use (that doesnt need opening references etc) is to have the parent class VI return an error code (ie a "method not implemented" error) - that way, any override VIs will execute normally, but any classes that do not provide this functionality will error in a known way that you can catch and handle appropriately, etc.


That's more or less what I did to have an indication of forgotten-to-implement overrides before we had the must-override option for methods. But for the use-case I have here this is not an option, since I'd have to call the method. In my use-case I need to know if it exists without actually calling it.

The open/close ref does the trick here and for my use-case it's not to much overhead.
---
Jeffrey
VIT

#7 MikaelH

MikaelH

    The 500 club

  • Premium Member
  • 575 posts
  • Location:Sydney
  • Version:LabVIEW 2012
  • Since:1996

Posted 24 August 2010 - 09:24 PM

The open/close ref does the trick here and for my use-case it's not to much overhead.

Especially when you open a VI reference by name i.e. using the string instead of path




Posted Image