Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2007

Tip: Looking for answers? Try searching our database.

Best practices question ... monitoring an objects contents ...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jamie Risk - 28 Jun 2007 17:56 GMT
I'm using a class in my project and I'd like to determine if the
any of the fields in the object have been modified since the
original instantiation.  For intent and purposes, the following
class is typical:

public class patient
{
  private string name;
  private string surname;

  public Name {
     get { return this.name; }
     set { this.name = value; }
  }
  public Surname {
     get { return this.surname; }
     set { this.surname = value; }
  }
}

The example is only meant to show that the class in question
isn't inheriting from another class.

Whether the modification check happens synchronously (through a
method or property access) or asynchronously (such as an event)
isn't all that important.  All that I'm trying to avoid is
re-doing the original class or inheriting from the original
class and overriding all the accessor methods.

Suggestions?
Peter Duniho - 28 Jun 2007 18:32 GMT
> I'm using a class in my project and I'd like to determine if the any of  
> the fields in the object have been modified since the original  
> instantiation.  For intent and purposes, the following class is typical:

I'm not sure what "best practices" has to do with anything here.  There  
are a variety of mechanisms by which the information you seek could be  
obtained, but what's the "best" way surely depends on how you want it to  
work, and what sort of access you have to the classes.

Assuming that semantically what you want to know is whether a mutable  
class is "dirty" (that is, has been instantiated with some specific  
values, at least one of which has subsequently been changed), I would just  
include a boolean flag in the class to indicate that state.  In any of  
your properties, have the setter also set the flag to true.  Then you  
could have a read-only property that retrieves the flag.

For example:

> public class patient
> {
[quoted text clipped - 15 lines]
>    }
> }

However, obviously you could accomplish this in a variety of other ways.  
For example, make the object cloneable and equatable, and then create a  
clone immediately after instantiation which you can then later compare for  
equality.  Or you could create an event (per-instance) or events  
(per-property) that are raised whenever a property is modified;  
subscribing to those events would tell you as it happens whether changes  
have occurred.  Or you could simply create a different data structure that  
has copies of the properties in question, which you then compare  
explicitly at a later point in time.  Or, some mechanism I haven't listed  
yet could be used instead of any of these.

Any or all of these are appropriate, depending on your needs and what the  
current architecture allows.

Pete
Jamie Risk - 28 Jun 2007 18:43 GMT
Save for the cloneable/equatable choices, I'd considered what
you wrote.

I was hoping there might be a class other than "object" I could
inherit from or an obscure CLR artifact that would track then
publish an event when contents of an object changed.

If such a creature existed I'd suggest that it would fall into
the "best practices" category.

Nonetheless, thanks!

>> I'm using a class in my project and I'd like to determine if the any
>> of the fields in the object have been modified since the original
[quoted text clipped - 49 lines]
>
> Pete
sloan - 29 Jun 2007 13:54 GMT
The CSLA framework does alot of this "IsDirty" stuff.

But its not a simple as just inheriting from something.

The framework is free (google "csla rocky") and you'll find it.

But you'll probably have to buy the book to understand what's going on.

(there is a vb.net and c# version of the book).

> I'm using a class in my project and I'd like to determine if the any of
> the fields in the object have been modified since the original
[quoted text clipped - 25 lines]
>
> Suggestions?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.