Re: The C++ Object Model: Good? Bad? Ugly?
On Nov 3, 4:25 pm, James Kanze <james.ka...@gmail.com> wrote:
On Nov 3, 8:44 pm, tonytech08 <tonytec...@gmail.com> wrote:
On Nov 1, 3:32 am, James Kanze <james.ka...@gmail.com> wrote:
On Nov 1, 4:02 am, tonytech08 <tonytec...@gmail.com> wrote:
What I like about the C++ object model: that the data
portion of the class IS the object (dereferencing an
object gets you the data of a POD object).
No it doesn't.
class SomePODClass
{
public:
int first_int;
int second_int;
void Func1(){}
};
SomePODClass X;
int first_int_in_obj = *(int*)&X; // this is not pretty, but true
But it's only true for POD types,
Well that's why I added the parenthetical part in my original post: to
make clear I was referring to what I like about the C++ model and wish
it wouldn't get abberated so quickly by changing the memory
representation of the data portion. 'POD' was very key for my thought,
though could have been worded better to show that I guess.
and only because of
constraints of C compatiblity. The data portion of the class
isn't the object in general.
I tend to think of the data portion (noun, vs. behavior=verb) as "the
thing" because that's what get's operated on and maybe even directly
manipulated. I'm not willing to go to a paradigm that only allows data
manipulation via class methods. That is way to high level and
constraining for me. A lot of people complain about C and C++ because
of the memory management, but for me, that's one of the things I like
about it! GC breaks MY programming model for example.
What I don't like about the C++ object model: that most OO
features are not available for class object design without
loss of POD-ness.
So, I'm more than leaning toward "bad" because of the
limitations and that the language doesn't distinguish what
is of very key importance. How do you feel about the
object model?
The "object model" in the C++ standard is very low-level.
Intentionally. It is designed for you to build on. The
object model of the classes you write is for you to design.
It can be more OO than many other languages (e.g. Java or
C#), when that's appropriate. Just as it can drop the OO
model completely when that's appropriate (e.g value
objects). The essential point of C++ is that it doesn't
impose any application level object model; it lets you use
whatever is appropriate.
It does restrict usage of OO concepts unless one jettisons the
"value object" concept, which is unfortunate (and
unnecessary?).
It restricts the use of OO concepts to classes designed to be
used with OO concepts.
Not really, since one can have POD classes with methods, just not
CERTAIN methods (you are suggesting that "classes designed to be used
with OO concepts" are those heavyweight classes that break PODness,
right?). You seem to be saying that POD classes are not supported or
at least not encouraged. That would be a real downer if true. I'd like
to see more support in the langauge for POD classes. I don't know how
much can be implemented before it becomes impossible. Certainly
initializing constructors can be had? Polymorphism not, but only NOT
because of the way C++ implements it?
It supports non OO concepts as well,
which are more appropriate in some cases.