OO Design for Specifc Problem
-
Hi Folks, I have a question about the best way to design / redesign my software. I have a program that uses a web services to perform certain tasks. Each task is a different set of request / response classes on the server end and a general function call from the Main Hook. EG.
RequestObject req = new RequestObject("SomeVal");
ResponseObject rsp = new ResponseObject();rsp = WebServiceHook.Method1(RequestObject); //Returns ResponseObject
Each Method takes a different request object and returns a different type of response object. As it stands i have a class for each of these methods, Each class has a public method Process() that does the interaction. I am trying to determine the best way to group all this code together using OO techniques without sacrificing functionality. I would like just one ProcessMethod in one class that will handle the interaction with the webservice for all the different web methods. So i would only call one ProcessMethod passing a switch of sorts that would define the relevant types and uniques strings that method requires. Some Sample code below:
\[ComVisible(false)\] private static InfoRequest infoReq = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD \[ComVisible(false)\] private static InfoResponse infoRsp = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD //PARAM TYPES WILL DIFFER IN EACH PROCESS METHOD public static bool Process(INTERFACEREQUEST COMReq, out INTERFACERESPONSE COMRsp) { bool blnReturnVal = false; //Always the same CInfoRsp InfoRsp = new CInfoRsp(); //TYPES WILL DIFFER IN EACH PROCESS METHOD CInfoReq InfoReq = (CInfoReq)COMReq; //TYPES WILL DIFFER IN EACH PROCESS METHOD Globals.dtStart = DateTime.Now; //Always the same Globals.Log(Logger.LogLevel.Minimum, Logger.LogType.APIMethodEntryPoint, "SOME TEXT HERE", "AND HERE", InfoReq.SalePointID);//Always the same - Except for the Piece of Text try { Globals.TheService.Url = Settings.URL; //Always the same infoReq = new InfoRequest(); //TYPES WILL DIFFER IN EACH PROCESS METHOD infoRsp = new InfoResponse(); //TYPES WILL DIFFER IN EACH PROCESS METHOD SetRequest(InfoReq); //Set the PHS Request Object = to Our Values Passed from the COM Component CallWEBServiceMethod(); //Call the Web Service passing the appropriate arguments
-
Hi Folks, I have a question about the best way to design / redesign my software. I have a program that uses a web services to perform certain tasks. Each task is a different set of request / response classes on the server end and a general function call from the Main Hook. EG.
RequestObject req = new RequestObject("SomeVal");
ResponseObject rsp = new ResponseObject();rsp = WebServiceHook.Method1(RequestObject); //Returns ResponseObject
Each Method takes a different request object and returns a different type of response object. As it stands i have a class for each of these methods, Each class has a public method Process() that does the interaction. I am trying to determine the best way to group all this code together using OO techniques without sacrificing functionality. I would like just one ProcessMethod in one class that will handle the interaction with the webservice for all the different web methods. So i would only call one ProcessMethod passing a switch of sorts that would define the relevant types and uniques strings that method requires. Some Sample code below:
\[ComVisible(false)\] private static InfoRequest infoReq = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD \[ComVisible(false)\] private static InfoResponse infoRsp = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD //PARAM TYPES WILL DIFFER IN EACH PROCESS METHOD public static bool Process(INTERFACEREQUEST COMReq, out INTERFACERESPONSE COMRsp) { bool blnReturnVal = false; //Always the same CInfoRsp InfoRsp = new CInfoRsp(); //TYPES WILL DIFFER IN EACH PROCESS METHOD CInfoReq InfoReq = (CInfoReq)COMReq; //TYPES WILL DIFFER IN EACH PROCESS METHOD Globals.dtStart = DateTime.Now; //Always the same Globals.Log(Logger.LogLevel.Minimum, Logger.LogType.APIMethodEntryPoint, "SOME TEXT HERE", "AND HERE", InfoReq.SalePointID);//Always the same - Except for the Piece of Text try { Globals.TheService.Url = Settings.URL; //Always the same infoReq = new InfoRequest(); //TYPES WILL DIFFER IN EACH PROCESS METHOD infoRsp = new InfoResponse(); //TYPES WILL DIFFER IN EACH PROCESS METHOD SetRequest(InfoReq); //Set the PHS Request Object = to Our Values Passed from the COM Component CallWEBServiceMethod(); //Call the Web Service passing the appropriate arguments
-
From reading about the OO patterns, it would appear the one i need to use is http://en.wikipedia.org/wiki/Abstract_factory_pattern[^] Am i correct in saying this?
KeithF wrote:
Am i correct in saying this?
Yes. You'd want an (abstract) base-class that defines the
Process
method;public abstract bool Process(BaseProcessArgs args)
{The factory would return a class that derives from this abstract base-class, with each class having it's own implementation for the
Process
method. The app would only have to call the method, without knowing specific details on the class. Varying the parameters can be done in a similar way;EventArgs
is a nice example on how to vary parameters, and still have some control. Imagine a base-class for the arguments, called "BaseProcessArgs"; if you'd need to pass a string and an int, your "Args" class would look like below;class TestArgs: BaseProcessArgs
{
public string TestString { get; set; }
public int TestInt { get; set; }
}Alternatively, if only types will change, you might want to consider a
generic
class.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
KeithF wrote:
Am i correct in saying this?
Yes. You'd want an (abstract) base-class that defines the
Process
method;public abstract bool Process(BaseProcessArgs args)
{The factory would return a class that derives from this abstract base-class, with each class having it's own implementation for the
Process
method. The app would only have to call the method, without knowing specific details on the class. Varying the parameters can be done in a similar way;EventArgs
is a nice example on how to vary parameters, and still have some control. Imagine a base-class for the arguments, called "BaseProcessArgs"; if you'd need to pass a string and an int, your "Args" class would look like below;class TestArgs: BaseProcessArgs
{
public string TestString { get; set; }
public int TestInt { get; set; }
}Alternatively, if only types will change, you might want to consider a
generic
class.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Folks, Question about my design so far, I am wondering if i am going about this the right way? I have a COM Library created in C#, with COMVisible set to true. This library talks to a 3rd party WebService calling various methods depending on the task at hand. For each Request / Response class exposed by the 3rd party DLL I have a Request / Response Pair (Class and Interface) to Marshal variables specifically for a VC6 application. Mainly using:
MarshalAs(UnmanagedType.LPStr)]
So with that in my i have added a C# project to the solution to test this code, see test method below:
static void Main(string[] args)
{
ICOMReq iReq = new CCOMReq();
ICOMRsp iRsp = new CCOMRsp();
Link l = new Link();iReq.Date\_Time = DateTime.UtcNow; iReq.Var2 = "1023758145865"; l.DoMethod1(iReq, out iRsp); //Handle COM Response here }
The link class looks like so at the moment be but will have all the methods created once the design is correct:
public class Link
{
public bool DoMethod1(ICOMReq _COMReq, out ICOMRsp COMRsp)
{
Method1 WebServiceMethod = new Method1(new Method1Request(), new Method1Response(), (CCOMReq)_COMReq, new CCOMRsp());
WebServiceMethod.Process();//Just test code at the moment COMRsp = null; return true; } }
Each DoMethod(N) that will be in the link class will look the same performing its task with identical code to the other DoMethods. The key differences between the methods is the Param Types Passed in and the Method1 (Method1Request/Method1Response) type will vary depending on the webmethod to be called. Class Method1 (There will be one of these for every method I need to implement on the WebService) looks like so:
public class Method1 : WebServiceInterfaceBridge { public Method1(Method1Request WEB\_Req, Method1Response WEB\_Rsp, CCOMReq COM\_Req, ICOMRsp COM\_Rsp) : base(WEB\_Req, WEB\_Rsp, CBE\_Req, CBE\_Rsp) { WEB\_Req.SOME\_DATE\_TIME = COM\_Req.Date\_Time; } public new void Process() { base.Process(); } public override void LOG() { Console.WriteLine(this.WebMethod\_Request.MEMBER\_VAR\_HERE);