473,842 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"All public methods should be virtual" - yes or no / pros & cons

I'm on a team building some class libraries to be used by many other
projects.

Some members of our team insist that "All public methods should be virtual"
just in case "anything needs to be changed". This is very much against my
instincts. Can anyone offer some solid design guidelines for me?

Thanks in advance....
Nov 15 '05
175 8932

<di********@dis cussion.microso ft.com> skrev i meddelandet
news:uN******** ******@TK2MSFTN GP11.phx.gbl...
If its private its for that class as you state, if its inherited from that
base class, its nolonger the same class so private should not be visible to the inherited class.

Thats logic.


It might be logic in C#, but not in C++.
The access specifiers public/protected/private does not control visibility
in C++, only accessibility.

--
Dag Henriksson
Nov 15 '05 #61
Doesnt make any sense to have it that way.
"Dag Henriksson" <da************ @hotmail.com> wrote in message
news:bv******** ****@ID-200546.news.uni-berlin.de...

<di********@dis cussion.microso ft.com> skrev i meddelandet
news:uN******** ******@TK2MSFTN GP11.phx.gbl...
If its private its for that class as you state, if its inherited from that base class, its nolonger the same class so private should not be visible

to
the inherited class.

Thats logic.


It might be logic in C#, but not in C++.
The access specifiers public/protected/private does not control visibility
in C++, only accessibility.

--
Dag Henriksson

Nov 15 '05 #62
<di********@dis cussion.microso ft.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Doesnt make any sense to have it that way.
That is merely an opinion. If it would not make any sense as you state, C++
language would have changed the concept.

Tom.
"Dag Henriksson" <da************ @hotmail.com> wrote in message
news:bv******** ****@ID-200546.news.uni-berlin.de...

<di********@dis cussion.microso ft.com> skrev i meddelandet
news:uN******** ******@TK2MSFTN GP11.phx.gbl...
If its private its for that class as you state, if its inherited from that base class, its nolonger the same class so private should not be
visible to
the inherited class.

Thats logic.


It might be logic in C#, but not in C++.
The access specifiers public/protected/private does not control visibility in C++, only accessibility.

--
Dag Henriksson


Nov 15 '05 #63
> > > there are times when it's useful.
Name one :-).
Can I just note, I wasn't trying to argue for or against private virtuals, just noting why they're different to protected virtuals :) However, Jim
Hyslop and Herb Sutter wrote a nice article that provided a reasonable
example: http://www.cuj.com/documents/s=8000/cujcexp1812hyslop/


Hehe, this article says it all. One C++ knoledgable person that loves the
fact that her code is smart and hard to grasp. The next developer needs to
go back to the first one before he can use the class properly. That is the
whole point, it isn't wrong but it works in a counter-intuitive way,
defeating the purpose of having these visibility layers.

Nice article.

Martin.
Nov 15 '05 #64
And what language do you think will be used most in the CLI world and where
the jobs are :D C#

"TT (Tom Tempelaere)" <_N************ **@hotmail.comM APSO_N_> wrote in
message news:wN******** ***********@pho bos.telenet-ops.be...
<di********@dis cussion.microso ft.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Doesnt make any sense to have it that way.
That is merely an opinion. If it would not make any sense as you state,

C++ language would have changed the concept.

Tom.
"Dag Henriksson" <da************ @hotmail.com> wrote in message
news:bv******** ****@ID-200546.news.uni-berlin.de...

<di********@dis cussion.microso ft.com> skrev i meddelandet
news:uN******** ******@TK2MSFTN GP11.phx.gbl...
> If its private its for that class as you state, if its inherited
from
that
> base class, its nolonger the same class so private should not be

visible to
> the inherited class.
>
> Thats logic.

It might be logic in C#, but not in C++.
The access specifiers public/protected/private does not control visibility in C++, only accessibility.

--
Dag Henriksson



Nov 15 '05 #65
Any developer who intentionaly obscufates code in any way is out on theyre
ear. We consider them bad designers.
"Martin Maat [EBL]" <du***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.com...
> there are times when it's useful. Name one :-).

Can I just note, I wasn't trying to argue for or against private

virtuals,
just noting why they're different to protected virtuals :) However, Jim
Hyslop and Herb Sutter wrote a nice article that provided a reasonable
example: http://www.cuj.com/documents/s=8000/cujcexp1812hyslop/


Hehe, this article says it all. One C++ knoledgable person that loves the
fact that her code is smart and hard to grasp. The next developer needs to
go back to the first one before he can use the class properly. That is the
whole point, it isn't wrong but it works in a counter-intuitive way,
defeating the purpose of having these visibility layers.

Nice article.

Martin.

Nov 15 '05 #66
I would take it further and say they are a risk to the organization and also
intentional damage and would highlight that to in any references to future
jobs.
<di********@dis cussion.microso ft.com> wrote in message
news:OQ******** ******@TK2MSFTN GP09.phx.gbl...
Any developer who intentionaly obscufates code in any way is out on theyre
ear. We consider them bad designers.
"Martin Maat [EBL]" <du***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.com...
> > there are times when it's useful.

> Name one :-).

Can I just note, I wasn't trying to argue for or against private

virtuals,
just noting why they're different to protected virtuals :) However, Jim Hyslop and Herb Sutter wrote a nice article that provided a reasonable
example: http://www.cuj.com/documents/s=8000/cujcexp1812hyslop/


Hehe, this article says it all. One C++ knoledgable person that loves the fact that her code is smart and hard to grasp. The next developer needs to go back to the first one before he can use the class properly. That is the whole point, it isn't wrong but it works in a counter-intuitive way,
defeating the purpose of having these visibility layers.

Nice article.

Martin.


Nov 15 '05 #67
> C# doesnt have the concept of "funtion prototypes" in header files because
the compiler can take care of that, why duplicate code for every method?
That is the fault of the design of C++ compilers so we have to do the work
for it.


Well, they didn't have these fancy editors back then that enabled the
programmer to collaps the implemantation did they? So seperating interface
and implementation was just practical, like more of C++'s design decisions
were practical when they were made. It was also a way to publish interfaces
without giving away the code. Because they didn't have type libraries back
then.

It is no use bashing C++ for all the things it doesn't have in 2004
(although I must admit it is great fun to get a rise out of those C++
preachers).
Nov 15 '05 #68
2004? When was C++ spec last updated ?

Function prototypes have NOTHING to do with collapse to definitions in the
VSnet IDE you cluless t.ard. Its there to be a forward reference to the
implementation. . Because the compiler needs to check so we are forced to
make up for that defecency. This could be easily fixed but its not.


"Martin Maat [EBL]" <du***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.com...
C# doesnt have the concept of "funtion prototypes" in header files because the compiler can take care of that, why duplicate code for every method?
That is the fault of the design of C++ compilers so we have to do the work for it.
Well, they didn't have these fancy editors back then that enabled the
programmer to collaps the implemantation did they? So seperating interface
and implementation was just practical, like more of C++'s design decisions
were practical when they were made. It was also a way to publish

interfaces without giving away the code. Because they didn't have type libraries back
then.

It is no use bashing C++ for all the things it doesn't have in 2004
(although I must admit it is great fun to get a rise out of those C++
preachers).

Nov 15 '05 #69
So, according to your bs its there to give away interfaces without code?
Pure BS. IT also gives away INTERNAL information, are you in the habbit of
giving out private internal definitions? Glad you dont work here.
"Martin Maat [EBL]" <du***@somewher e.nl> wrote in message
news:10******** *****@corp.supe rnews.com...
C# doesnt have the concept of "funtion prototypes" in header files because the compiler can take care of that, why duplicate code for every method?
That is the fault of the design of C++ compilers so we have to do the work for it.
Well, they didn't have these fancy editors back then that enabled the
programmer to collaps the implemantation did they? So seperating interface
and implementation was just practical, like more of C++'s design decisions
were practical when they were made. It was also a way to publish

interfaces without giving away the code. Because they didn't have type libraries back
then.

It is no use bashing C++ for all the things it doesn't have in 2004
(although I must admit it is great fun to get a rise out of those C++
preachers).

Nov 15 '05 #70

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

164
8069
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be changed". This is very much against my instincts. Can anyone offer some solid design guidelines for me? Thanks in advance....
0
9870
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10671
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7035
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5696
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5884
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3142
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.