I have a class with a Name
property, where the name is set by the end-user. In order to ensure compatibility with the rest of the environment, and to avoid rejecting a lot of inputs, some processing of the name is done automatically:
public string Name {
get { return _Name; }
set {
if (value == null)
return;
_Name = value.Replace("/", "-").Replace("%", "pct").Replace("&", "-").Replace("'", "").Trim();
_RawName = value;
}
}
My concern is about encapsulation and SRP.
I wonder if something like no processing, and then a method such as myObject.processName()
would be better from a principles point of view (and if I am right thinking it is not as clear as my current implementation).
I have carefully read a similar question, but is discusses validation only, and this goes further, and the data is manipulated.
-- There is no beginner
tag here, so let me put it here. I am new to all this, please forgive any stupid questions :)