|
-
February 25th, 2009, 09:56 AM
#31
Re: Multiple Inheritance and Casting
and encapsulating some orthogonal (or mostly orthogonal) aspect of the behavior of the instantiated host class.
Would you be able to expand on this in POE (Plain Old English)
I'm not entirely sure I understand the meaning of 'orthogonal' in this context. 
(orthogonal usually means "at right angles to")
Last edited by JohnW@Wessex; February 25th, 2009 at 09:58 AM.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
February 25th, 2009, 10:38 AM
#32
Re: Multiple Inheritance and Casting
 Originally Posted by JohnW@Wessex
Would you be able to expand on this in POE (Plain Old English)
I'm not entirely sure I understand the meaning of 'orthogonal' in this context.
(orthogonal usually means "at right angles to")
John,
I am suprised that someone would post a link to material for reference when they have problems understanding the first paragraph of the linked material.. 
Simply draw a diagram, inheritance is represented by vertical lines. A reference between peer classes as a horizontal line. Definately "right angles".
In the code sample that was posted, one would presume that the Printer classes knew how to convert "content" to "byte patterns: that would be understood by a given printer, and the Comm class would know how to transfer bytes across a media (USB, Serial, etc).
Therefore the Template class would typically implement the functionallity of taking the bytes output by the printer (base class #1) and passing them to the communications (base class #2).
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
February 25th, 2009, 10:59 AM
#33
Re: Multiple Inheritance and Casting
Okay looking in further detail at the Double Dispatch idea, I still don't really see how I can make use of it. At least not with the current code base (which I am stuck with).
Looking at the Foo/Bar example, I would think my "Modes" in this case would be the "Bar" classes, and then the objects which use the Modes would then be the "Foo" class (assuming I follow correctly).
One problem in my situation is that the Foos out number the bars by far. There are potentially hundreds of different locations where I need to call functions on the modes. So defining multiple functions in each of those locations gets quite time consuming and annoying.
Another problem is that in the examples that I have looked at, the base class has the same members as the child class. This is not the case in my situation. For my situation the SpecialMode classes have methods unique to those modes. So I need to access it as a "SpecialMode" in order to access those methods.
However I feel like maybe I am missing something with the Double Dispatch.
Eggman
Using: VS 2008 w. Net 3.5
-
February 25th, 2009, 11:06 AM
#34
Re: Multiple Inheritance and Casting
 Originally Posted by Eggman002
One problem in my situation is that the Foos out number the bars by far. There are potentially hundreds of different locations where I need to call functions on the modes. So defining multiple functions in each of those locations gets quite time consuming and annoying.
But that is a "fact of life". If I add a capability to a few hundred classes (my industrial automation library has over 5000 different control elements) and there is no direct relationship between them (IS-A), then it DOES mean going into a few hundred files and adding the code.
Now in many cases this can be minimized. If you have a group of conceptually related methods which by definition have a common grouping (but not an inheritance relationship), then simply use a #include to simplify the legwork..
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
February 25th, 2009, 11:17 AM
#35
Re: Multiple Inheritance and Casting
I am suprised that someone would post a link to material for reference when they have problems understanding the first paragraph of the linked material..
I just googled for "c++ template policy" and that link popped up first. I understood the concepts described, it was just the word 'orthogonal' was unfamiliar for me in a programming context. Seems obvious now
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
February 26th, 2009, 08:23 AM
#36
Re: Multiple Inheritance and Casting
 Originally Posted by TheCPUWizard
But that is a "fact of life". If I add a capability to a few hundred classes (my industrial automation library has over 5000 different control elements) and there is no direct relationship between them (IS-A), then it DOES mean going into a few hundred files and adding the code.
Now in many cases this can be minimized. If you have a group of conceptually related methods which by definition have a common grouping (but not an inheritance relationship), then simply use a #include to simplify the legwork..
Actually I think I understand a way that I can use this technique now that I have thought about it a bit. As per my previous example if I have a SpecialModeCommon, then I can use the SpecialModeCommon as a wrapper so that I have something like this:
Code:
class SpecialModeCommon
{
public:
static void ACommonFunction(SpecialModeType1 mode)
{
// Process SpecialModeType1
ACommonFunctionCommonCode(...);
}
static void ACommonFunction(SpecialModeType2 mode)
{
// Process SpecialModeType2
ACommonFunctionCommonCode(...);
}
private:
static void ACommonFunctionCommonCode(...)
{
// Common Code goes here.
}
}
Then elsewhere if I need to call ACommonFunction I can just do:
SpecialModeCommon::ACommonFunction(mode);
And it should call the correct function and do the processing correctly. And in my hundreds of locations I only need to put one line of code.
I like this solution. It doesn't require any special casting or checking of types at runtime. I can re-use a fair amount of the code.
Thanks for all the help.
Eggman
Using: VS 2008 w. Net 3.5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|