Method Design Help - delegates dont help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tim Smith (timasmith_at_hotmail.com)
Date: 08/26/04


Date: 25 Aug 2004 18:16:25 -0700

I have 20-50 methods (C# or Java) with the following identical content
which I wish to write only once!

public SomeObjOrVoid MethodDiffSigEachTime(SomeParams p) {
   ResouceObj resObj = null;
   ResourceTrans resTran = null;
   SomeObjOrVoid returnVal = null;
   try {
      resObj = GetResource();
      resTran = resObj.StartTrans();
      // METHOD SPECIFIC CODE GOES HERE
   } catch (Exception e) {
      LogError(e);
   } finally {
      resObj.Close();
      resTran.Close();
   }
   return returnVal;
}

I tried to use reflection but I cant pass in the method name since it
is a helper method and if I use a hard coded string (risking runtime
types), it loses on performance and exceptions lose a lot of
information.

There must some way to design around duplicating so much code for this
service orientated architecture...



Relevant Pages

  • Method Design Architecture guidance needed...
    ... I have 20-50 methods (C# or Java) with the following identical content ... public SomeObjOrVoid MethodDiffSigEachTime{ ... ResouceObj resObj = null; ... } catch (Exception e) { ...
    (comp.object)
  • Design perfect method - help!
    ... I have 20-50 methods (C# or Java) with the following identical content ... public SomeObjOrVoid MethodDiffSigEachTime{ ... ResouceObj resObj = null; ... service orientated architecture... ...
    (comp.lang.java)