:: Re: [DNG] Experiencing with GtkBuil…
Kezdőlap
Delete this message
Reply to this message
Szerző: Rainer Weikusat
Dátum:  
Címzett: dng
Tárgy: Re: [DNG] Experiencing with GtkBuilder
Steve Litt <slitt@???> writes:

> On Sun, 22 Nov 2015 13:13:47 +0000
> Rainer Weikusat <rainerweikusat@???> wrote:
>
>> Edward Bartolo <edbarx@???> writes:
>> > Is it possible to use classes and objects while using gtk2/3? I
>> > noticed that only functions are used and that class use is ovoided
>> > by prepending functions with a group string. As far as I know, C can
>> > still use structs that are attached to a set of data and a set of
>> > functions, but without inheritance and polymorphyism.
>>
>> C structs can be embedded into each other which means they can
>> 'inherit' other structs, eg, for a totally contrived example
>>
>> struct something {
>>     int number0, number1;
>> };

>>
>> struct another {
>>     struct something parent;
>>         int drei;
>> };

>
> That's composition, not inheritance. It's "has-a", not "is-a". You need
> to name the whole chain when calling an element (someth->anoth->drei
> rather than someth->drei).


That's the implementation without any compiler support hiding its
details. There's also no independent 'something object' involved here
whose identity could change.

[...]

> * Encapsulation
> * Inheritance
> * Polymorphism
>
> In my personal opinion, Encapsulation is by far the strongest benefit,
> and in fact I seldom use inheritance and almost never use
> polymorphism.


'Encapsulation' is something which exists by virtue of using abstract
interfaces. And if you look at this:

void print_result(struct something *sth)
{
    printf("Result: %d\n", calc(sth));
}


you ought to note that the code doesn't access the implementation of the
passed object but invokes an abstract function with a pointer and hence,
will work with different objects: That's exactly what 'encapsulation' is
about.