[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    protected vs private (was Re: kdeui library inconsistency in
From:       Stefan Taferner <taferner () salzburg ! co ! at>
Date:       1998-02-24 7:52:37
[Download RAW message or body]

At 16:09 23.2.1998 +0000, you wrote:
>Stefan Taferner wrote:
>> 
>> At 09:17 13.2.1998 +0100, you wrote:
>> >Today I got a sudden urge to derive the KNewPanner class and enhance it
>> >a bit. What I tried to do was, basically, making a double-click on the
>> >divider cause the divider to hide/show. Just a problem:
>> >
>> >The eventFilter method in KNewPanner is private - but in QObject it is
>> >virtual public. There might be religion about this, but I think one
>> >should never "privatizise" a virtual public method [...]
>> 
>> Yes, this method should not be private.
>> 
>> IMO one has to have a very good reason to use private at all. Protected
>> is restricting enough for most cases.
>
><OO bigot mode on>
>
> IMHO private is better than protected because it makes the base class
>more encapsulated.

If you write a class, and you encapsulate everything very strict (most methods
private instead of protected), you have to be really good and foreseeing.

Otherwise you will for sure forget the one or the other way that somebody
wants to extend (read: inherit) your class.

I have been annoyed from many classes that use most things private
for non obvious reasons.

> protected allows anyone to use the method by deriving from the base
>class.

Yes, that's what it is for.  You can either write end-user classes that
virtually nobody can inherit because the interface is of not much use,
or you trust in people (and your programming skills) and open things
offering protected to most internals.

--Stefan

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic