I have a class Server
which talks to a server connection for IRC. It holds a list of known User
s, and creates them as necessary.
I have two problems involving the User
class:
- Anyone can create an instance of a
User
. I only want theServer
class to be able to do this. - If a user (the thing
User
describes) changes his/her name (or other info, like joined channels), theServer
class can change it itself. However, other classes can, too! I want to disallow other classes from touching this information (making it read-only to them).
How can I solve these two problems? In C++, it can be solved by using the friend
keyword and making the ctor and setName
(and such) private.
Is there a C# keyword which can allow a certain method be accessable by a specified class? This would solve my problem.