Bit of a noob question but:
I have a custom class defined as:
public class Icon
{
string name;
int value;
public void setName(string nameIn)
{
name = nameIn;
}
public void setValue(int valueIn)
{
value = valueIn;
}
}
Is it better to update the object attributes (in this case from an array of type Icon) from another class in the same application domain using:
fm.iconData[0].setName("Plum");
OR is it better to set by changing my instance variable modifiers in the Icon class to ‘public’ and use:
fm.iconData[0].name = "Plum";
Is this breaking any OO design concepts?
Neither. In this case use a property instead of a public field or explicit setter/getter methods:
Properties are compiled down to setter/getter methods which allows you to change your internal implementation later on if required so still respects encapsulation. Explicit setter/getter methods are not idiomatic for C#.
Also see MSDN on properties.