I am creating a class in C# and am being told that all of my properties should be public. I was taught that information hiding is common in C++ but idk if it is the same is C# or if the convention for doing so is different. The first example is how I was taught to do it. The 2nd example is how I am being taught to implement this class now. My question is this: Will this prevent me from using any of the properties with other classes or will it all work because of the constructor making them public?
Thank you all in advance
class Book
{
string Title = null;
string Author = null;
int Year = 0;
string CoverType = null;
public Book (string aTitle, string anAuthor, int aYear, string aCoverType)
{
Title = aTitle;
Author = anAuthor;
Year = aYear;
CoverType = aCoverType;
}
Separation of examples
public class Book
{
public string Title = null;
public string Author = null;
public int Year = 0;
public string CoverType = null;
public Book (string aTitle, string anAuthor, int aYear, string aCoverType)
{
Title = aTitle;
Author = anAuthor;
Year = aYear;
CoverType = aCoverType;
}