Saturday, November 13, 2010

..........Observer Pattern

Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.


// Suppose you are working with a data set and you call AcceptChanges after deleting some row. Than all rows objects updated accordingly.This is the best example of Observer patterns

//Create Dataset
Dataset objDs = new Dataset();

//Read data from database in Dataset
//Fill data set here

MessageBox.Show( objDs.RowState.ToString());
// You will get Added.

objDs.Tables(0).Rows(0).Item(0)=”Hello”;

MessageBox.Show( objDs.RowState.ToString());
// You will get Modified.

objDs.AcceptChanges();

MessageBox.Show( objDs.RowState.ToString());
// You will get Unchanged.

No comments:

Followers

Link