Re: Lahman, how ya doing?



In article <d5m6lr$q9e$1@xxxxxxxxxxxxxxxxxxxxx>,
Andrew McDonagh <news@xxxxxx> wrote:
>Gregory L. Hansen wrote:
>> In article <d5iuj1$pl7$1@xxxxxxxxxxxxxxxxxxxxx>,
>> Andrew McDonagh <news@xxxxxx> wrote:
>>
>>>Gregory L. Hansen wrote:
>>>
>>>>In article <0%Qde.43511$4v.31435@trndny03>,
>>>>H. S. Lahman <hsl@xxxxxxxxxxxxxxxxx> wrote:
>>>>
>>>>
>>>>>Responding to Hansen...
>>>>
>>>>
>>>>>class EventElement
>>>>>{
>>>>>private:
>>>>> Object* recipient;
>>>>> int event_id;
>>>>> int tick_count;
>>>>>public:
>>>>> EventElement (Object* r, int e, int t)
>>>>> {recipient = r; event_id = e; tick_count = t;};
>>>>> int getTickCount() {return tick_count;};
>>>>>}
>>>>
>>>>
>>>>Let me ask you, why is this a class? I usually think of classes as
>>>>something with member functions that do things with the data. I would
>>>>have used a struct as a passive holder of data.
>>>>
>>>>
>>>
>>>For one thing, it allows us to create instances which are immutable objects.
>>>
>>>For another, we can use polymorphic calls with a class over a struct
>>>('c' struct I take it you mean - as C++ structs are the same as Classes
>>>but with different default access rights).
>>
>>
>> Thanks, Andrew, but I'm not sure that meant anything to me.
>>
>
>I haven't been following this thread closely, but it appears you are
>using C++.

Yes, C++.

>
>> Immutable objects? Can't be changed?
>
>Correct, can't be changed, but can be queried.
>
>> Is that better than a const struct?
>
>I C++ a Struct and a Class are actually the same thing - choosing to use
>one over the other, simply implies what default visibility you want.
>
>In the case of the Class code above, whilst the EventElement is created
>with three parameters, only tick_count is accessible to other objects,
>as its the only member var with a get() method.
>
>In this case, the use of a Class (and actually the use of the 'private:'
>is ensuring encapsulation - all members are private.
>
>So, is it better than a const struct? I'd say in this example yes,
>simply because we don't want to expose the other two member vars.
>
>Your Mileage may vary.

Towards the end of my recent message to Lahman I posed a problem where I
want to tell an object of one class to get data from an object of another
class sometimes from one member function and sometimes from another member
function. Except there's no easy way I know of to use a pointer to a
member function, so I'd thought of using public variables as an interface.
That seems related to what you'd just said above. Any comments on my new
shenanigan?

--
"Experiments are the only means of knowledge at our disposal. The rest is
poetry, imagination." -- Max Planck
.