jgcode Posted May 6, 2009 Report Share Posted May 6, 2009 Red File = Red colored class in picture - is a file format of a KKD FileDP & For = Displacement and Force - is a processing method of a file but is not tied to a specific format.Class HierarchyKKD File as ParentRed File as Child of KDD File DP & For as Child of KDD FileProblemI want to select a file format e.g. Red File Load File Method then call a processing method e.g. DP & For Process MethodEssentially I have different file types AND I have different processing methods for files.Both operate on KKD File Class (which contains the data) but I want to be able to choose the format AND processing method - not have the processing method tied to the file format or vice versa.I tried to downcast to the parent then upcast to the processing method?The above generates an error (due to dynamic dispatch I guess) but is there a way to do this?Can I jump through the hierarchy like this?Can I code the above somehow?Or can anyone suggest a better class hierarchy?I was trying to avoid a separate independent class as both classes operate on a File so I thought they should inherit from KKD File and be siblings?Any suggestions?Cheers JG Quote Link to comment
shoneill Posted May 6, 2009 Report Share Posted May 6, 2009 QUOTE (jgcode @ May 5 2009, 05:47 PM) Any suggestions?Cheers JG No i don't think this can be done like that. Both sibling classes could have totally different member data and methods so there's no way for the compiler to automatically know how to convert one to another, if it's even possible. You'll need to write a converter VI to do the work for you. I don't think this can be automated in the way you want. Casting down (towards parent) is fine but casting across or forward is not possible. Bear in mind the ACTUAL class type is important here, not the "assumed" type. Man I wish I knew the proper syntax to explain what I mean.... I'll leave it up to somebody else with more accurate terminology to avoid confusion. Shane. Ps You can have classes IN classes (as member objects: "File format" as an object and "Operations" as an object) so you could use one class to load the file and another class to perform the operations. This way you can mix to your heart's content. You'll soon realise the flexibility of this and start converting EVERYTHING to classes..... Quote Link to comment
PaulL Posted May 6, 2009 Report Share Posted May 6, 2009 Shane's suggestion to use the composite relationship is a good one. You could make DP & For a class that is part of the KKD class (or even make it separate, but let's keep it contained inside KKD for now). As far as I can see there is really no reason for DP & For to be a child of KKD anyway. Then KKD can just pass itself as an input (not for dynamic dispatching, but as a regular input on a separate terminal) to a DP & For method, and KKD's children can use the method, too. If things get much more complicated you may want to take a look at the Strategy pattern. Paul Quote Link to comment
shoneill Posted May 6, 2009 Report Share Posted May 6, 2009 QUOTE (Paul_at_Lowell @ May 5 2009, 06:27 PM) Shane's suggestion to use the composite relationship is a good one.You could make DP & For a class that is part of the KKD class (or even make it separate, but let's keep it contained inside KKD for now). As far as I can see there is really no reason for DP & For to be a child of KKD anyway. Then KKD can just pass itself as an input (not for dynamic dispatching, but as a regular input on a separate terminal) to a DP & For method, and KKD's children can use the method, too. If things get much more complicated you may want to take a look at the Strategy pattern. Paul ^^^^^^ ¦ ¦ ¦ ¦ ¦ ¦ See what I mean: "composite relationship" and "Strategy pattern". Cool. Shane. Quote Link to comment
Mark Yedinak Posted May 6, 2009 Report Share Posted May 6, 2009 It sounds like you are doing something along the lines of a decorator pattern. Quote Link to comment
Aristos Queue Posted May 6, 2009 Report Share Posted May 6, 2009 QUOTE (Mark Yedinak @ May 5 2009, 12:59 PM) It sounds like you are doing something along the lines of a decorator pattern. Or delegation... implementation of Delegation in LabVIEW available here. Quote Link to comment
jgcode Posted May 7, 2009 Author Report Share Posted May 7, 2009 Thanks everyone. Very much appreciated Will look at all the above, make some changes and let you know 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.