Here's a specific problem that I run into when creating objects, such as collections, that need to be available through the whole scope of the application.
I have the following class:
class UserDataCollection
{
List<UserData> Collection = new List<UserData>();
UserData current;
public UserData Current
{
get { return current; }
set
{
current = value;
}
}
public UserDataCollection( UserData userdata )
{
this.current = userdata;
}
public void Add ( UserData item )
{
Collection.Add(item);
}
}
Now for every UserData object I want to add, it's going to create a new List object each time I go UserDataCollection datacoll = new UserDataCollection(userdata);
So my objects will never be added to the same collection, which is not the point of this collection.
Is this then a good singleton case or just create the object at Application Init and use the same object throughout?
What's the best design practice for something like this?