Thoughts on... "Fetching" a readonly "version" of a object from its editable "version"Thoughts on... "Fetching" a readonly "version" of a object from its editable "version"
Old forum URL: forums.lhotka.net/forums/t/2602.aspx
juddaman posted on Wednesday, March 28, 2007
Is it appropriate to allow readonly objects to be fetched from a editable object. For example make a PersonInfo from a Person.
public static PersonInfo GetPersonInfo(Person p)
{
return new Person(p);
}
private PersonInfo(Person p)
{
_Name = p.Name;
}
Thanks, George.
juddaman replied on Wednesday, March 28, 2007
oops thats should have been:
public static PersonInfo GetPersonInfo(Person p)
{
return new PersonInfo(p);
}
private PersonInfo(Person p)
{
_Name = p.Name;
}
hurcane replied on Wednesday, March 28, 2007
There is no right or wrong way to to do this. In my opinion, I would not use a static method for this. Since you are requiring passing in an instance of Person, I would make GetPersonInfo an instance method that takes no parameters.
Copyright (c) Marimer LLC