Friday, April 3, 2009

Properties (Getters and Setters)

Today is another break-through or relevation so to speak.

This might be trivial, although I recently discovered that storing the data for later use may not require caching, viewstates or sessions.

Interesting as it be, data can be stored in properties (VB.Net specific) or simply Getters and Setters in the general object-orientation methology sense.

It is important to note that this will only work if you are not deviating from the current class.

How did this came in handy for me? Web development tends to rely on UI objects on the web page. So much so that we forget that essentially the "code-behind" contains of methods wrap within a class.

Hence, using OO methology, we can simply create a property (getters and setters) to maintain data for any data that we would like to preserve.

Example. (VB.Net code)
Public Property orderByStr() As String
Get Return _OrderBy End Get
Set(ByVal value As String) _OrderBy = value End Set
End Property

In this case, for example, I had a data table that I wanted to sort by a certain order.

To determine whether I would have the table ordered by ascending or descending order, I simply use the property above. This can also be expanded to determine how to sort if the previous sorting column is different than the current one.


So much so for a relevation. I was brought down despite thinking that this may work.
Someone proof me wrong but I ended up caching.

Disappointment

No comments:

Post a Comment