473,851 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why C# doesn't support "friend" relationship?


It's so messy w/o the "friend" relationship. Does anyone know why it was
not supported in C#. It's almost about as bad as it doesn't support the
inheritance hierarchy and method reference (calling tree) browsing that is
supported in C++. I don't know how some could write a large scale
object-oriented application w/o those. If you have overcome these
limitations in C#, please share your thoughts and ideas. Thanks!


Nov 15 '05 #1
43 2860

1) Friend is not so great in and of itself, but that aside
you have "internal" and "protected internal"...

2) View/Class View from main menu and you can browse to
your hearts content...
-----Original Message-----

It's so messy w/o the "friend" relationship. Does anyone know why it wasnot supported in C#. It's almost about as bad as it doesn't support theinheritance hierarchy and method reference (calling tree) browsing that issupported in C++. I don't know how some could write a large scaleobject-oriented application w/o those. If you have overcome theselimitations in C#, please share your thoughts and ideas. Thanks!

.

Nov 15 '05 #2
Zeng <zz*@nonospam.c om> wrote:
It's so messy w/o the "friend" relationship. Does anyone know why it was
not supported in C#. It's almost about as bad as it doesn't support the
inheritance hierarchy and method reference (calling tree) browsing that is
supported in C++.
Hang on - "browsing" sounds like it's something to do with the IDE, not
with the language itself. Or have I misunderstood?
I don't know how some could write a large scale
object-oriented application w/o those. If you have overcome these
limitations in C#, please share your thoughts and ideas. Thanks!


Having not done much C++, I can't say there have been many times where
I've thought, "Ah, what I really need here is friend access." Internal
is usually fine - especially if you don't mind having a separate
assembly for each subsystem in your app. Occasionally I've felt it
would be nice to have a namespace access level, like package access in
Java (although possibly without its implicit protected access), but
that's been pretty rare.

I can't say it's really been a barrier to writing C#.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
"In general, friend functions are frowned upon in C++ because it breaks the
natural encapsulation. As a general rule, you should pick your friends with
care, as you don't want just anyone tinkering with your private parts."

http://www.juicystudio.com/tutorial/cpp/friend.asp

"Zeng" <zz*@nonospam.c om> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

It's so messy w/o the "friend" relationship. Does anyone know why it was
not supported in C#. It's almost about as bad as it doesn't support the
inheritance hierarchy and method reference (calling tree) browsing that is
supported in C++. I don't know how some could write a large scale
object-oriented application w/o those. If you have overcome these
limitations in C#, please share your thoughts and ideas. Thanks!

Nov 15 '05 #4
100
Hi Zeng,

Even though, I miss *friend* once in a while I dont't thing that is a big
loss.
When you declare a type as inner of other type. The former is friend of the
outer and has unlimited access to all memebers. Doesn't work the other way
arround, though. I mostly used *friend* in c++ when I was overloading the
operators with global functions. However, it is not the case with .NET.
In addition you have *internal* access modifier.
Actually I believe that *friend* methods could make the big mess if it is
not used sparingly.

About the second part of the question. Yes, you have all this in the *class
viewer*. This is IDE feature and has nothing to do with C#, C++ or any other
language, though.
HTH
B\rgds
100
It's so messy w/o the "friend" relationship. Does anyone know why it was
not supported in C#. It's almost about as bad as it doesn't support the
inheritance hierarchy and method reference (calling tree) browsing that is
supported in C++. I don't know how some could write a large scale
object-oriented application w/o those. If you have overcome these
limitations in C#, please share your thoughts and ideas. Thanks!

Nov 15 '05 #5
- Virtual protected internal methods trigger compiler warnings that we can't
turn it off individually.
- Class Resident has Police as a friend (in C++), if you put Police to the
same assembly then it won't be able to be in the assemply with other classes
like PoliceOffice
- If i'm going to modify a core code (let's say a method), how do I use
View/ClassView to find out quickly which code will be impacted by my
changes? In C++ IDE, I would have to see who reference the method, who
inherits the class, and most of the times who references it's overriden
methods, and trace it along the inheritence hierarchy and sideway to other
related methods. Right now, in C#, I would have to do a "find in files"
operation for each single mouse click that I used to do with C++ IDE and
still don't have the same overall relationship picture.
-View/Class View doesn't tell who inherit your class, it only tell you who
your class inherits.

"Richard" <ri******@amgen .com> wrote in message
news:09******** *************** *****@phx.gbl.. .

1) Friend is not so great in and of itself, but that aside
you have "internal" and "protected internal"...

2) View/Class View from main menu and you can browse to
your hearts content...
-----Original Message-----

It's so messy w/o the "friend" relationship. Does anyone

know why it was
not supported in C#. It's almost about as bad as it

doesn't support the
inheritance hierarchy and method reference (calling tree)

browsing that is
supported in C++. I don't know how some could write a

large scale
object-oriented application w/o those. If you have

overcome these
limitations in C#, please share your thoughts and ideas.

Thanks!


.

Nov 15 '05 #6

Because we only have 1 IDE (as least that I know of) available for C#, so
practically the IDE limitation has everything to do with C#, and woud
someone dare to develop their own IDE for C# to compete with MS? Or maybe MS
will write another IDE for C++ users?
"100" <10*@100.com> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
Hi Zeng,

Even though, I miss *friend* once in a while I dont't thing that is a big
loss.
When you declare a type as inner of other type. The former is friend of the outer and has unlimited access to all memebers. Doesn't work the other way
arround, though. I mostly used *friend* in c++ when I was overloading the
operators with global functions. However, it is not the case with .NET.
In addition you have *internal* access modifier.
Actually I believe that *friend* methods could make the big mess if it is
not used sparingly.

About the second part of the question. Yes, you have all this in the *class viewer*. This is IDE feature and has nothing to do with C#, C++ or any other language, though.
HTH
B\rgds
100
It's so messy w/o the "friend" relationship. Does anyone know why it was not supported in C#. It's almost about as bad as it doesn't support the
inheritance hierarchy and method reference (calling tree) browsing that is supported in C++. I don't know how some could write a large scale
object-oriented application w/o those. If you have overcome these
limitations in C#, please share your thoughts and ideas. Thanks!


Nov 15 '05 #7
I have no comments on comparing the two IDE's but there is an alternative to
VC#.

http://www.icsharpcode.net/
--
Bobby C. Jones
http://code.AcadX.com

"Zeng" <zz*@nonospam.c om> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

Because we only have 1 IDE (as least that I know of) available for C#, so
practically the IDE limitation has everything to do with C#, and woud
someone dare to develop their own IDE for C# to compete with MS? Or maybe MS will write another IDE for C++ users?
"100" <10*@100.com> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
Hi Zeng,

Even though, I miss *friend* once in a while I dont't thing that is a big
loss.
When you declare a type as inner of other type. The former is friend of the
outer and has unlimited access to all memebers. Doesn't work the other way arround, though. I mostly used *friend* in c++ when I was overloading the operators with global functions. However, it is not the case with .NET.
In addition you have *internal* access modifier.
Actually I believe that *friend* methods could make the big mess if it is not used sparingly.

About the second part of the question. Yes, you have all this in the

*class
viewer*. This is IDE feature and has nothing to do with C#, C++ or any

other
language, though.
HTH
B\rgds
100
It's so messy w/o the "friend" relationship. Does anyone know why it

was not supported in C#. It's almost about as bad as it doesn't support the inheritance hierarchy and method reference (calling tree) browsing
that is supported in C++. I don't know how some could write a large scale
object-oriented application w/o those. If you have overcome these
limitations in C#, please share your thoughts and ideas. Thanks!



Nov 15 '05 #8
Zeng,
Have you looked into Refactoring and some of the C# Refactoring tools?

http://www.refactoring.com

See the .NET section for C# tools:
http://www.refactoring.com/tools.html

Refactoring is a technique to restructure code in a disciplined way.

What I have been doing in VB.NET is applying the Obsolete Attribute to the
element (method, class, field) that I intend on modifying, then I get a list
of warnings every place that element is used. I then proceed with the
Refactoring as normal.

Hope this helps
Jay

"Zeng" <zz*@nonospam.c om> wrote in message
news:ut******** ******@TK2MSFTN GP09.phx.gbl...
- Virtual protected internal methods trigger compiler warnings that we can't turn it off individually.
- Class Resident has Police as a friend (in C++), if you put Police to the
same assembly then it won't be able to be in the assemply with other classes like PoliceOffice
- If i'm going to modify a core code (let's say a method), how do I use
View/ClassView to find out quickly which code will be impacted by my
changes? In C++ IDE, I would have to see who reference the method, who
inherits the class, and most of the times who references it's overriden
methods, and trace it along the inheritence hierarchy and sideway to other
related methods. Right now, in C#, I would have to do a "find in files"
operation for each single mouse click that I used to do with C++ IDE and
still don't have the same overall relationship picture.
-View/Class View doesn't tell who inherit your class, it only tell you who
your class inherits.

"Richard" <ri******@amgen .com> wrote in message
news:09******** *************** *****@phx.gbl.. .

1) Friend is not so great in and of itself, but that aside
you have "internal" and "protected internal"...

2) View/Class View from main menu and you can browse to
your hearts content...
-----Original Message-----

It's so messy w/o the "friend" relationship. Does anyone

know why it was
not supported in C#. It's almost about as bad as it

doesn't support the
inheritance hierarchy and method reference (calling tree)

browsing that is
supported in C++. I don't know how some could write a

large scale
object-oriented application w/o those. If you have

overcome these
limitations in C#, please share your thoughts and ideas.

Thanks!


.


Nov 15 '05 #9
no debugger, thts why that IDE sucks.
"Bobby C. Jones" <bobbyj (at) acadx (dot) com> wrote in message
news:uH******** ******@TK2MSFTN GP11.phx.gbl...
I have no comments on comparing the two IDE's but there is an alternative to VC#.

http://www.icsharpcode.net/
--
Bobby C. Jones
http://code.AcadX.com

"Zeng" <zz*@nonospam.c om> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

Because we only have 1 IDE (as least that I know of) available for C#, so
practically the IDE limitation has everything to do with C#, and woud
someone dare to develop their own IDE for C# to compete with MS? Or maybe
MS
will write another IDE for C++ users?
"100" <10*@100.com> wrote in message
news:ej******** ******@TK2MSFTN GP11.phx.gbl...
Hi Zeng,

Even though, I miss *friend* once in a while I dont't thing that is a

big loss.
When you declare a type as inner of other type. The former is friend of the
outer and has unlimited access to all memebers. Doesn't work the other way arround, though. I mostly used *friend* in c++ when I was overloading the operators with global functions. However, it is not the case with
..NET. In addition you have *internal* access modifier.
Actually I believe that *friend* methods could make the big mess if it is not used sparingly.

About the second part of the question. Yes, you have all this in the

*class
viewer*. This is IDE feature and has nothing to do with C#, C++ or any

other
language, though.
HTH
B\rgds
100

> It's so messy w/o the "friend" relationship. Does anyone know why
it was
> not supported in C#. It's almost about as bad as it doesn't support

the > inheritance hierarchy and method reference (calling tree) browsing

that
is
> supported in C++. I don't know how some could write a large scale
> object-oriented application w/o those. If you have overcome these
> limitations in C#, please share your thoughts and ideas. Thanks!



Nov 15 '05 #10

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

Similar topics

1
2241
by: timbobd | last post by:
I have encountered a situation that I don't understand. When I call a sub of Friend scope (in an object with Friend scope), I am getting an error "Public member 'subname' not found in type 'myType'". Any idea why? Since Friend scope should be visible within my assembly, and everying is taking place within a single project, I don't understand why this error is occuring. Here is some illustrative code, where I would get the error in the...
2
1568
by: Vark | last post by:
Interesting behavior I came across today where a child form has full access to a base form class' controls, but you can only modify the controls' properties in code, not in the visual designer. Here's how you can reproduce it: New Winforms project On Form1, drop a visual control. I'll use a panel in this example. Make sure Panel1 modifier is set to "Friend" Build project Add another form - this one an inherited form. Set it to inherit...
3
2274
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte() on WebForm1.aspx, I use "Public Property" and I declare variable _oRpte as Friend Shared. That's my problem. If I don't declare _oRpte as Friend Shared, I can't use WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend Shared, I can use...
1
2299
FLEB
by: FLEB | last post by:
I'm working on a PHP/MySQL site with social networking and "message blast" functionality, and I'm not sure what the best method to represent multiple levels of interpersonal relationships in the database would be. What I'd like to happen is this: A user posts a message to their page, with a "blast radius" option. The system then sends the message that many levels outward from the original person: A radius of 1 would go to their friends, a...
0
9897
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
9747
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,...
0
11019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9506
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...
1
7906
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7073
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
5933
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4143
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3179
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.