Does the C# FCL implement a Listener interface or methods?

  • Thread starter Thread starter Roger Helliwell
  • Start date Start date
R

Roger Helliwell

Hey guys,

Subject line says it all. I have many presentation layer objects that
need to be notified when a specific business-tier class has been
modified.

Thanks,
Roger
 
There is no specific implementation for Listener interfaces in the FCL.
Notification from business objects to presentation is done through events in
the business objects.
 
Hey Roger,

You should use events in your business-tier classes which would be raised
when the business class has been modified. The presentation layer objects
would then subscribe to that events to receive notifications they are
interested in.

For example:

//////////////////////
// Business tier
//////////////////////
public class Customer
{
...
private string _firstName;

public event EventHandler FirstNameChanged;

public string FirstName
{
get
{
return _firstName;
}
set
{
_firstName = value;
if (null != FirstNameChanged)
{
FirstNameChanged(this, EventArgs.Empty);
}
}
}
}

////////////////////////////
// Presentation tier
////////////////////////////

public class MyForm: Form
{
private Customer _customer;

public MyForm()
{
InitializeComponent();

_customer = new Customer();
_customer.FirstNameChanged += new
EventHandler(CustomerFirstNameChangedHandler);
}

private CustomerFirstNameChangedHandler(object sender, EventArgs e)
{
// React on first name change.
}
}
 
Hey Roger,

You should use events in your business-tier classes which would be raised
when the business class has been modified. The presentation layer objects
would then subscribe to that events to receive notifications they are
interested in.

For example:

//////////////////////
// Business tier
//////////////////////
public class Customer
{
...
private string _firstName;

public event EventHandler FirstNameChanged;

Thanks Dmitriy, that was exactly what i was looking for. I didn't even
know C# had an 'event' keyword! My Deitel & Deitel book barely
mentions it. Thanks again.

Roger
 
Back
Top