How to implement dirty flag in .net 1.1  
Author Message
R.Tutus





PostPosted: .NET Framework Data Access and Storage, How to implement dirty flag in .net 1.1 Top

Hi,

I put declared my account class with all properties: Name, BillDate......

in my account data layer accountDALC I implement the updateAccount function that updates the database with the modified account object.

The thing is that I want to call updateAccount function only if the account object has been changed by the user since the last time I updated the database.

I guess in my account class, whenever I update the object, I need to put a mecanism saying that the account object has been changed,so that i can take that into consideration. And when the user clicks Save button. If the acount has changed then I call updateAccount function otherwise I do nothing.

So how do I implement that. what s a good practice for that please.

Let me also know if there are any articles for this pls

Thanks for your help.




.NET Development14  
 
 
David Hayden





PostPosted: .NET Framework Data Access and Storage, How to implement dirty flag in .net 1.1 Top

There are a number of solutions. You could do something like:

public class Account : DomainObject
{
private string _name = string.Empty;
public string Name
{
get { return _name; }
set {
if (_name.Equals(value))
return;
_name = value;
MarkDirty();
}
}

}

You will probably have a layer supertype for domain objects that holds common functionality:

abstract public class DomainObject
{
private bool _isDirty;
virtual public bool IsDirty
{
get { return _isDirty; }
}

protected void MarkDirty()
{
_isDirty = true;
}
}

Regards,

Dave



 
 
R.Tutus





PostPosted: .NET Framework Data Access and Storage, How to implement dirty flag in .net 1.1 Top

What did you use abstract and virtual for. I have never used those and I don t know what they used for in this scenario. In plain and simple english pls:)

Thanks a lot



 
 
David Hayden





PostPosted: .NET Framework Data Access and Storage, How to implement dirty flag in .net 1.1 Top

Abstract means you can't instantiate the DomainObject as in:

// Won't Work... DomainObject is abstract.
DomainObject domainObject = new DomainObject();

You can only inherit from it-

public class Account : DomainObject

Virtual means you are giving inherited classes the option of overriding the IsDirty property if they want to redefine it. Maybe Account is dirty if it or the _address class is dirty, hence you could redefine IsDirty in the Account Class:

public class Account : DomainObject
{

override public bool IsDirty
{
get
{
return (_isDirty || _address.IsDirty);
}
}

}

Hope this helps,

Dave