Jump to content

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


Recommended Posts

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.

post-906-027340100 1282557549_thumb.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.

Link to comment

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

Link to comment

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.

Link to comment

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.