The goal question is toward the bottom of the post.
Setup
Complex Object:
Class AObject (
property BCollection
…
)
Class BCollection (
property CCollection
…
)
Class CCollection()
I have a class that populates the object then that class calls a different class method that saves the object
Class Populate
{
Public void PopulateObject()
{
….
DataProvider.SaveObject()
}
}
Class DataProvider
{
Public void SaveObject
{
Foreach (b in BCollection)
{
…
// event call one that b was entered in database.
}
}
}
Class InsertForm : Form
{
// Goal is to make this line work in the best practice
Populate.event += OnTheFormHandler
}
Now InsertForm has no visibility to DataProvider what is the best way to define an event in DataProvider so that its EventHander can be used in the Form and its delegate in PopulateObject
Goal:
What I am trying to avoid is declaring two sets of events one for each class like….
Class Populate
{ delegate void PopulateProcess(..)
Public event PopulateProcess Processed
Public void PopulateObject()
{
….
DataProvider.Processed += new DataDelegate(DataProcess)
DataProvider.SaveObject()
}
Public DataProcess ()
{
If (Process != null)
Process(…)
}
}
Class DataProvider
{
delegate void DataDelegate (..)
Public event DataDelegate DataProcess;
Public void SaveObject
{
Foreach (b in BCollection)
{
…
// event call one that b was entered in database.
OnProcess()
}
}
Public OnProcess()
{
If (DataProcess != null)
DataProcess(this, new EventArg(…)
}
}
Class InsertForm : Form
{
// Goal is to make this line work in the best practice
Populate. Processed += new PopulateProcess (OnTheFormHandler)
}
Thanks in advance
Setup
Complex Object:
Class AObject (
property BCollection
…
)
Class BCollection (
property CCollection
…
)
Class CCollection()
I have a class that populates the object then that class calls a different class method that saves the object
Class Populate
{
Public void PopulateObject()
{
….
DataProvider.SaveObject()
}
}
Class DataProvider
{
Public void SaveObject
{
Foreach (b in BCollection)
{
…
// event call one that b was entered in database.
}
}
}
Class InsertForm : Form
{
// Goal is to make this line work in the best practice
Populate.event += OnTheFormHandler
}
Now InsertForm has no visibility to DataProvider what is the best way to define an event in DataProvider so that its EventHander can be used in the Form and its delegate in PopulateObject
Goal:
What I am trying to avoid is declaring two sets of events one for each class like….
Class Populate
{ delegate void PopulateProcess(..)
Public event PopulateProcess Processed
Public void PopulateObject()
{
….
DataProvider.Processed += new DataDelegate(DataProcess)
DataProvider.SaveObject()
}
Public DataProcess ()
{
If (Process != null)
Process(…)
}
}
Class DataProvider
{
delegate void DataDelegate (..)
Public event DataDelegate DataProcess;
Public void SaveObject
{
Foreach (b in BCollection)
{
…
// event call one that b was entered in database.
OnProcess()
}
}
Public OnProcess()
{
If (DataProcess != null)
DataProcess(this, new EventArg(…)
}
}
Class InsertForm : Form
{
// Goal is to make this line work in the best practice
Populate. Processed += new PopulateProcess (OnTheFormHandler)
}
Thanks in advance