Delegates problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My query was realated to delegates

My purpose for using delegate is to invoke dynamically a function from a particular class,

It is like thi

Class A
Transaction main clas

Class
Controller class

WINDOWS UI .
final UI

Now I got a kind of requirement like two phase commitment. It means first one is to commit the records into DB, next is to write that data into a magantic strip with a help of hardware. If this writing of data into hardware fails , then this records written to database should be rolled back. But i do not have control to manually commit the records, i have to rely on Class A.
So when called from UI to save the records, first it go to Class A, save the records, then uses delegate. This is invoke class B's method. Because Class B is the one which does the funcationalities of with UI. Here, class B's method is acutally a function pointed by Class A's delegate. Here I am struck. I am not able to invoke like this. But I guess this way it is possible to be done. I am looking for your help at this place
If this is been done, then class B's method will notify Class A whether writing of data to magantic strip was successfull or failure. When Class A finally gets update on this, it can decide on commiting the records or to roll back

Hope to get your updates

Thanks and Regards,
Sach
 
The best method I see to implement this is:

Interface IControllerInterface { bool WriteWhateverToStrips(); }

class A
{
private IControllerInterface myController = null;
public A(IControllerInterface i)
{
this.myController = i;
}
public void WriteWhatever() {
StartTransaction();
WriteWhatever();
if(myController != null)
{
if(myController.WriteWhateverToStrips())
{
CommitTransaction();
}
else
{
RollbackTransaction();
}
}
else
{
// Commit or rollback, if there's no interface set, whatever you
want
}
}
}

class B : IControllerInterface
{
public bool WriteWhateverToStrips()
{
if(WriteYourDataToTheMagneticStrip() == Succesful)
{
return true;
}
return false;
}
}

I don't see how using delegates would be any better than this in this case.

Hope this helps,
Javier Campos

Sachi said:
My query was realated to delegates.

My purpose for using delegate is to invoke dynamically a function from a particular class,

It is like this

Class A
Transaction main class

Class B
Controller class.

WINDOWS UI .
final UI.

Now I got a kind of requirement like two phase commitment. It means
first one is to commit the records into DB, next is to write that data into
a magantic strip with a help of hardware. If this writing of data into
hardware fails , then this records written to database should be rolled
back. But i do not have control to manually commit the records, i have to
rely on Class A.
So when called from UI to save the records, first it go to Class A,
save the records, then uses delegate. This is invoke class B's method.
Because Class B is the one which does the funcationalities of with UI. Here,
class B's method is acutally a function pointed by Class A's delegate. Here
I am struck. I am not able to invoke like this. But I guess this way it is
possible to be done. I am looking for your help at this place.
If this is been done, then class B's method will notify Class A
whether writing of data to magantic strip was successfull or failure. When
Class A finally gets update on this, it can decide on commiting the records
or to roll back.
 
Back
Top