Design Pattern : Urgent RRS feed

  • Question



    I am using Dotnet  version 2.0.
    I need a idea about the abstract factory pattern(using interface) how to implement it, can anybody please help me:

    I have got 2 documents Doc1 and Doc2.
    I have got 5 workflow WF1,WF2,WF3,WF3,WF4,WF5.


    Doc1 has to perform following workflow : WF1,WF3,WF4
    Doc2 has to perform following workflow : WF1,WF2,WF3,WF3,WF4,WF5.

    Going forward we can add documents like say Doc 3.Which will have already existing Workflow and can also add new workflow if required.

    I need a design idea in this.Can this me XML based workflow too.

    Its really urgent,


    Thanks in advance


    Thursday, January 17, 2008 7:47 PM

All replies

  • hi robin,

    are u referring to some thing like this. u need to create objects WF!, Wf2, wf3 through Doc1 and then wf1,wf2,wf3 etc through doc2 and then also  looking on how to add new factory objects that would work on existing workfolow (i mean additional objects) and or new ones. I mean injection of new factories dynamically on run time.

    sorry, if i am confusing you, but i am not getting ur point.




    Friday, January 18, 2008 7:36 AM
  • Hi,

    Sorry if i confused u.


    My basic idea is how can my this requirement be implemented.Can it be done through factory pattern.


    The requirement is.

    I have got 2 document type : Doc1 and Doc 2.


    Now each document has to undergo certain Work FLow process, so that it gets processed fully.


    Assume as of today the existing Workflows(These are concrete classes) are WF1, WF2, WF3, WF4,WF5.


    Doc1 has to undergo WF1,WF3 and WF4 to get fully processed.

    Doc2 has to undergo WF1, WF2, WF3, WF4,WF5.


    I want the design in such a way so that in future assume a new documnet type say Doc3 is introduced in the system and also a new workflow say WF6.

    Doc3 has to undergo WF1,WF4,WF6 to get it processed.


    What would be the best design approach for this. so that enhancement like introducing Doc3 can be done with minimal change.


    Hope i am clear now.




    Friday, January 18, 2008 4:28 PM
  • To add to it..

    Assume i get Doc1 as input i should be only creating object of workflow( WF1,WF3 and WF4 ) and not of Workflow(Wf2 and Wf5).

    Friday, January 18, 2008 4:40 PM
  • yes this can definetly be done. will get back to you on how best it can be done.

    a few moments. :-)



    Friday, January 18, 2008 4:44 PM
  • Thx i am really waiting for it.

    Just a thought can the whole process be a XML driven too.


    I am using dotnet 2.0 version


    Friday, January 18, 2008 4:47 PM

    hi robin,

    this could be one of the solution using the factory pattern but using a choice .

    u have two documents doc1 and doc2 and u are to make individual documents . each of the documents differ in the way the work flow processes are executed.

    ur example, seems to directly relate to a car factory where in different models of the same car is being manufactured . for example may be different versions of honda cars, all designed and manfactured in a same factory.


    now solution could be like this:


    create a factory class that has a returndocument method. the input parameter to the returndocument is the document type that u want to return. now let there be two more classes that implements these two documents say document A and document B. in the document A class, we can agrregrate the classes WF1, WF2, WF3 and in the document B class you aggregrate WF2,WF3,WF4. [perhaps u instaniate the class and set some properties therein in some of the WF* classes].


    u may create abstract base classes for the factory and the doc at first. now create a class that would invoke the right factory method based on the document type required. this class will have two parameters - one the generic or rather the anstract factory object and the document type.


    inside the implementation of this method, it would call the getdocument method of the factory with the documen type.


    am i confusing you. ?

    the flow is something like this. the client calls the getdocument with the document type. the factory looks for the type of the document and then invokes the right method that would in return the document with the workflow instaniated.


    in case, u want to have a new document enlisted simply derive the document from the abstract document class . you can then add the workflow sequence as you like and give it a new name as u have said doc3. if you want to implement a new workflow, then u can implement it as concrete classes as u have already done with the workflow.


    this way, the user don't have to worry about what document class to call etc, he simply has to call the factory and the document type. ur factory would call the right document and return to him.


    from the developers point of view, this would also be easier to mantain as because now u can workflow classes on the fly and increase the return type of documents by simply inserting say if statement to check what document type is required and then calling the right method.


    this problem could also have been solved using interfaces, but then with interfaces, you might have problems while introducing new workflows, types etc . abstract classes are good over interfaces atleast in versioning.


    let me know if there's some doubt or if u require a sample code to understand the solution slightly better | or if i have confused u.








    Friday, January 18, 2008 7:50 PM
  • yes as i have mentione based on ur instatianation in say docA class, the workflow wf1, wf3 etc will depend. so, u are free to say any number and any combination of workflows.


    regarding the XML, i am not getting the point . can u elaborate on it


    Friday, January 18, 2008 8:00 PM
  • First of all thx a lot.

    It would be great if you could help me with a sample code in the mean time let me try to develop this.

    If i am done i will kep you posted.

    Friday, January 18, 2008 8:18 PM
  • Regarding XML i mean to say for a document i will mention there respective workflow in the XML tag .

    Will instantiate the object one by one based on it.












    Friday, January 18, 2008 8:21 PM
  • oh yes, if u do so that in xml, this would further reduce the workload .

    for example in the constructor of the doccreation class u could read the xml file say using xmltextreader and then depending on the workflow you would then call the instaniate the work flow objects.


    one immediate flexibility that i see is that work flows now could be removed or added as needed.

    second is that instead of multiple document types classes like documentA and documentB, you can now create a single document class that would read the XML file and instaniate.



    Friday, January 18, 2008 8:30 PM
  • Hi,

    Thx for the reply.


    Could you please help me with some code snippet if possible.



    Tuesday, January 22, 2008 9:30 PM