C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

proposal for implimentation only methods in a class

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Bruce Mellows
Guest





PostPosted: Wed Aug 03, 2005 6:55 am    Post subject: proposal for implimentation only methods in a class Reply with quote



A problem exists that methods specific to the implimentation of a
classes behaviour, namely its private non-virtual methods must be
declared on the class declaration.

If one could define methods for a class that do not override a virtual
method (but may overload a non-virtual method), and that these methods
are given the priviledge of private only, thus a class declaration need
only contain methods that are significant to a user of the declaration.

A supplied private implimentation only method has static linkage, such
that it cannot be referenced outside of the translation unit.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Victor Bazarov
Guest





PostPosted: Wed Aug 03, 2005 5:50 pm    Post subject: Re: proposal for implimentation only methods in a class Reply with quote



Bruce Mellows wrote:
Quote:
A problem exists that methods specific to the implimentation of a
classes behaviour, namely its private non-virtual methods must be
declared on the class declaration.

Why is that a problem?

Quote:
[...]

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Bruce Mellows
Guest





PostPosted: Wed Aug 03, 2005 11:10 pm    Post subject: Re: proposal for implimentation only methods in a class Reply with quote



The problem is that I need to declare the implimentation in the
interface.

eg.

class A
{
public:
A();
~A();
// ... etc
void user_visible_method_1();
void user_visible_method_2();
private:
void user_visible_methods_common_implimentation();
};

Why does the user of either user_visible_method need to know that there
is a method named user_visible_methods_common_implimentation? I believe
that they don't.

So that I am proposing that the private method
user_visible_methods_common_implimentation need not be declared, but
only defined in the c (cc, cpp, cxx, c++, C, whatever) file, and that
it would be assumed to be private, this further allows us to
change/re-factor the implimentation without having to re-compile every
user, which is a big deal when the project gets larger

Of course there is the constraint that these sort of implimentation
only methods do not change the 'shape' of the class, ie. they cannot
override a virtual, though they might overload a method.

This may also be usable for not declaring nested private classes in the
header, and only putting them in the implimentation file, these might
inherit from some interface and forward it to the main class, such that
the class can conform to an interface in its implimentation but not in
its interface.

I personaly see some value in it, and hope that there would not be much
work in acheiving this from the compiler vendors perspective (you are
allowed to add to namespaces at any time, why not classes)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Marc Schoolderman
Guest





PostPosted: Thu Aug 04, 2005 12:29 am    Post subject: Re: proposal for implimentation only methods in a class Reply with quote

Bruce Mellows wrote:

Quote:
Why does the user of either user_visible_method need to know that there
is a method named user_visible_methods_common_implimentation? I believe
that they don't.

Have you read Marshall Cline's faq?

http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.6

Furthermore, there exist idioms you can use to hide implementation
details. For example, the handle/body pattern;

http://www.gotw.ca/gotw/024.htm

Why _your_ proposal won't work: if an inline memberfunction of a class
needs the private member, it has to know it's signature, as well as that
the private member needs to have external linkage.

~Marc.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Bruce Mellows
Guest





PostPosted: Thu Aug 04, 2005 1:10 am    Post subject: Re: proposal for implimentation only methods in a class Reply with quote

Yes, I have read the FAQ, but I don't work with people who have, and if
I tell them that some 'idiom' can help to separate our inteface and
implimentation, ..., well not much separation is going to get done
(Think Bob from Conversations).

Regarding using some pattern or idiom to circumvent this need, perhaps
it might be nice to go direct rather than via a workaround ? (You can
get from New York to New Jersey by air - perhaps via Los Angeles if you
want, or you could get there easier by cab)

You're absolutely correct about an inline method needing the signature.
So it stands to reason that you would not be able to call it from
there, just like you cannot call any undeclared method or function - a
fine limitiation I would expect.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Carl Barron
Guest





PostPosted: Fri Aug 05, 2005 11:00 pm    Post subject: Re: proposal for implimentation only methods in a class Reply with quote

In article <1123109337.867536.228580 (AT) g47g2000cwa (DOT) googlegroups.com>,
Bruce Mellows <bruce+101 (AT) wakethegimp (DOT) org> wrote:

Quote:
The problem is that I need to declare the implimentation in the
interface.

eg.

class A
{
public:
A();
~A();
// ... etc
void user_visible_method_1();
void user_visible_method_2();
private:
void user_visible_methods_common_implimentation();
};

Why does the user of either user_visible_method need to know that there
is a method named user_visible_methods_common_implimentation? I believe
that they don't.

So that I am proposing that the private method
user_visible_methods_common_implimentation need not be declared, but
only defined in the c (cc, cpp, cxx, c++, C, whatever) file, and that
it would be assumed to be private, this further allows us to
change/re-factor the implimentation without having to re-compile every
user, which is a big deal when the project gets larger

Of course there is the constraint that these sort of implimentation
only methods do not change the 'shape' of the class, ie. they cannot
override a virtual, though they might overload a method.

This may also be usable for not declaring nested private classes in the
header, and only putting them in the implimentation file, these might
inherit from some interface and forward it to the main class, such that
the class can conform to an interface in its implimentation but not in
its interface.

I personaly see some value in it, and hope that there would not be much
work in acheiving this from the compiler vendors perspective (you are
allowed to add to namespaces at any time, why not classes)

what is wrong with the pimple idiom easiest implimented as:

class Foo
{
struct Bar;
tr1::shared_ptr<Bar> pimple;
public:
//...
};

or unnamed namespaces in the implimentation file?

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Bruce Mellows
Guest





PostPosted: Mon Aug 08, 2005 1:15 am    Post subject: Re: proposal for implimentation only methods in a class Reply with quote

It does preclude you from having any inlines for one thing.

But not to worry, the door seems to be closed.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.