I am designing a class which comprises of objects of other classes, right now i am accepting the values to instantiate this class via function parameters. This class is created per session(From the user login to logout). For a session the UserInteraction object will be global i.e:- It can be used from any file at any time. I am planning to allocate memory to the object at user login so that at every user login the object will be ‘new’.
However i am getting a feeling that i am not doing things right. Please advice if I can use any other patterns to improve the code.
class UserInteraction
{
private UserDetails _loginDetails; // information of the user logged in.
private UserFiles[] _userFilesDownloaded; // files downloaded for the user.
private PrintStatus _printStatus; // Details of files printed
public UserInteraction() { }
public UserDetails UserInfo {
get { return _loginDetails; }
set { _loginDetails = value; }
}
public PrintStatus Status {
get { return _printStatus; }
set { _printStatus = value; }
}
public UserFiles[] FilesDownloaded {
get { return _userFilesDownloaded; }
set { _userFilesDownloaded = value; }
}
}
Before you design some class at least be clear with its responsibilities and collaborations (other objects that it depends on , to perform its responsibilities).
Try to think who will instantiate/use this object, its life time and how/when it will be destroyed.
Be clear with these fundamental design principles http://en.wikipedia.org/wiki/Solid_(object-oriented_design).
As mentioned by @Thomas Levesque,”Don’t try to apply patterns where they’re not needed…”, they are just extensions to good design principles.