Z
Zerex71
Greetings,
I've been puzzling over a programming issue for a little while and
wanted to get some help with it. Here's the issue: I want to have a
common base class called Matrix1x3 to hold three numbers. When I
subclass from Matrix1x3 to form Vector, I want the three numbers to be
doubles or floats. When I subclass from Matrix1x3 to form
Orientation, I want the three numbers to be Angle-s (another class
which encapsulates the functionality of operating on three different
representations of a double-valued angle - degrees, radians, and
mils). In other words, I want to use 1x3 matrices in my program, but
one type is for vector operations and the other is for operations on
orientations of pitch, roll, and yaw. Maybe I can't even do this, I
don't know. I was wondering if there was a way to maybe have the base
class contain some raw variant type that could be refined based on
each subclass...help me out here...
I think it might be kind of "useless" if the base class did not
contain the raw data members, but it seems as if what I want to do
would preclude storing any common data in the class, so then I have to
ask myself what the purpose would be of even having the base class in
the first place.
Furthermore, I wondered to myself, if I had a base class that had a
method "transpose()" for example (being the name, after all, of a
basic matrix operation):
a) Would I be forced to implement (and use/invoke) "transpose()" in
the subclass, since it was extended from the Matrix1x3 class?
b) Would there be any way that I could just use or invoke
Matrix1x3::transpose() without having to "go through" the subclass?
Another example - Let's say both Matrix1x3 and Vector have an "add()"
method, which means they each know how to add themselves. If I
actually implemented the code in Matrix1x3's add(), could I just get
by with calling Matrix1x3::add() in Vector::add()? (I admit that
adding matrices is kind of trivial, but there could be more
complicated operations which could be shared by both classes.)
I guess what I am trying to do is figure out the appropriate way to
write OO-based math code, in essence.
I realize this problem could apply to both Java and C++ but since it
grew out of some Java programming I wanted to post it here. Thanks in
advance for any suggestions.
Mike
I've been puzzling over a programming issue for a little while and
wanted to get some help with it. Here's the issue: I want to have a
common base class called Matrix1x3 to hold three numbers. When I
subclass from Matrix1x3 to form Vector, I want the three numbers to be
doubles or floats. When I subclass from Matrix1x3 to form
Orientation, I want the three numbers to be Angle-s (another class
which encapsulates the functionality of operating on three different
representations of a double-valued angle - degrees, radians, and
mils). In other words, I want to use 1x3 matrices in my program, but
one type is for vector operations and the other is for operations on
orientations of pitch, roll, and yaw. Maybe I can't even do this, I
don't know. I was wondering if there was a way to maybe have the base
class contain some raw variant type that could be refined based on
each subclass...help me out here...
I think it might be kind of "useless" if the base class did not
contain the raw data members, but it seems as if what I want to do
would preclude storing any common data in the class, so then I have to
ask myself what the purpose would be of even having the base class in
the first place.
Furthermore, I wondered to myself, if I had a base class that had a
method "transpose()" for example (being the name, after all, of a
basic matrix operation):
a) Would I be forced to implement (and use/invoke) "transpose()" in
the subclass, since it was extended from the Matrix1x3 class?
b) Would there be any way that I could just use or invoke
Matrix1x3::transpose() without having to "go through" the subclass?
Another example - Let's say both Matrix1x3 and Vector have an "add()"
method, which means they each know how to add themselves. If I
actually implemented the code in Matrix1x3's add(), could I just get
by with calling Matrix1x3::add() in Vector::add()? (I admit that
adding matrices is kind of trivial, but there could be more
complicated operations which could be shared by both classes.)
I guess what I am trying to do is figure out the appropriate way to
write OO-based math code, in essence.
I realize this problem could apply to both Java and C++ but since it
grew out of some Java programming I wanted to post it here. Thanks in
advance for any suggestions.
Mike