I've got a singleton class like this.
class UserInteraction
{
private CustomerInformation _loginDetails;
private MusicDetails[] _musicFilesDownloaded;
private static volatile UserInteraction _interactionObject = null;
private static object syncRoot = new Object();
private UserInteraction()
{
}
public static UserInteraction Instance
{
get
{
if (_interactionObject == null)
{
lock (syncRoot)
{
if (_interactionObject == null)
_interactionObject = new UserInteraction();
}
}
return _interactionObject;
}
}
public CustomerInformation UserInfo
{
get
{
return _loginDetails;
}
set
{
_loginDetails = value;
}
}
public MusicDetails[] FilesDownloaded
{
get
{
return _musicFilesDownloaded;
}
set
{
_musicFilesDownloaded= value;
}
}
public void PurgeContents()
{
}
public void SerializeValues()
{
}
}
I can use the following code to access this singleton class
UserInteraction.Instance.UserInfo.CardData = "";
My questions are as follows
1) As you can see I can read/write into UserInfo structure, that means i can any number of copy of UserInfo. Is this against the laws of SingleTon?
2) If this is against the law of Singleton, how can i prohibit the duplication of UserInfo at the same time assign values into it?
Thanks.