| the session variables is kept up to date. This property also shows the use of a private setter, so that the value in the session variable can only be set under the control of facade class.
The Username property demonstrates a value that may once have been stored as a session variable but is no longer stored this way.
The following code shows how a session variable can be accessed through the facade. Note that there is not need to do any casting in this code.
// Save a session variable MyApplicationSession.StartDate = DateTime.Today.AddDays(-1); // Read a session variable DateTime startDate = MyApplicationSession.StartDate;
Additional Benefits An additional benefit of the facade design pattern is that it hides the internal implemention from the rest of the application. Perhaps in the future you may decide to use another mechanism of implementing session-state, other than the built-in ASP.NET HttpSessionState class. You only need to change the internals of the facade - you do not need to change anything else in the rest of the application.
Summary The use of a facade for HttpSessionState provides a much more robust way to access session variables. This is a very simple technique to implement, but with great benefit. 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] |