T
Tony Johansson
Hello!
This class Card displayed below is from a book called "Visual Studio 2005".
Now to my question here they haved used accessibility of public for the two
field suit and rank
This is completely wrong I changed it to private and the example application
containing this class Card works just as good as having the accessibility
set to public.
Do you agree with me?
There is almost never acceptable to have a field set to public.
namespace Ch10CardLib
{
public class Card
{
public readonly Suit suit;
public readonly Rank rank;
private Card() {}
public Card(Suit newSuit, Rank newRank)
{
suit = newSuit;
rank = newRank;
}
public Rank Rank
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}
public Suit Suit
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}
public override string ToString()
{
return "The " + rank + " of " + suit + "s";
}
}
}
//Tony
This class Card displayed below is from a book called "Visual Studio 2005".
Now to my question here they haved used accessibility of public for the two
field suit and rank
This is completely wrong I changed it to private and the example application
containing this class Card works just as good as having the accessibility
set to public.
Do you agree with me?
There is almost never acceptable to have a field set to public.
namespace Ch10CardLib
{
public class Card
{
public readonly Suit suit;
public readonly Rank rank;
private Card() {}
public Card(Suit newSuit, Rank newRank)
{
suit = newSuit;
rank = newRank;
}
public Rank Rank
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}
public Suit Suit
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}
public override string ToString()
{
return "The " + rank + " of " + suit + "s";
}
}
}
//Tony