Property on business objects - getting and setting
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-04-01T07:07:23Z
Indexed on
2010/04/01
7:13 UTC
Read the original article
Hit count: 275
Hi,
I am using LINQ to SQL for the DataAccess layer. I have similar business objects to what is in the data access layer.
I have got the dataprovider getting the message #23. On instantiation of the message, in the message constructor, it gets the MessageType and makes a new instance of MessageType class and fills in the MessageType information from the database.
Therefore; I want this to get the Name of the MessageType of the Message.
user.Messages[23].MessageType.Name
I also want an administrator to set the MessageType
user.Messages[23].MessageType = MessageTypes.LoadType(3);
but I don't want the user to publicly set the MessageType.Name. But when I make a new MessageType instance, the access modifier for the Name property is public because I want to set that from an external class (my data access layer).
I could change this to property to internal, so that my class can access it like a public variable, and not allow my other application access to modify it.
This still doesn't feel right as it seems like a public property. Are public access modifiers in this situation bad? Any tips or suggestions would be appreciated.
Thanks.
© Stack Overflow or respective owner