design question about collections, or how to accomplish

Discussion in 'Java' started by glunk, Jun 30, 2004.

  1. glunk

    glunk Guest

    Hi. As you can tell from my rapid posts, I am struggling with a design
    issue. I am not happy with the design (or lack thereof) which has occured in
    the subsystem that I am working on. No one has yet tried to use this
    subsystem, so I do not have to worry about changing the interface. So I am
    trying to fix it. But since I am new to Java, when to use what is confusing
    to me.

    I have a class called PdfDocWriter. It has a bunch of instance variables for
    things that are needed to create the PDF (pdfOutputFileName, templateName,
    acribatVersion...) There are 3 methods that I want, writeDocToPrint(),
    writeDocToImaging() and a private deleteFdF.

    This is all the info necessary to create the PDF except for the name and
    value for each field on the acrobat form.

    I need a structure for an indeterminant number of name / value pairs. When
    an application (application form for applying for loans) is created, they
    will be able to use the class I am designing simply by giving the instance
    vars their info and supplying this name / value pair thing.

    I am planning to have a class for PdfValues with 2 attributes. Then for the
    ConsolidationApplicationPdf class, I will use a collection of the PdfValues.
    Does this seem a good way to go?

    I am sorry if I am asking for basic info or if it seems like I am asking you
    to solve my business problems for me. I wish I had someone around here on
    whom I could bounce around ideas. But I do not.

    Thanks

    S
    glunk, Jun 30, 2004
    #1
    1. Advertising

  2. glunk

    Andy Fish Guest

    "glunk" <> wrote in message
    news:...
    > Hi. As you can tell from my rapid posts, I am struggling with a design
    > issue. I am not happy with the design (or lack thereof) which has occured

    in
    > the subsystem that I am working on. No one has yet tried to use this
    > subsystem, so I do not have to worry about changing the interface. So I am
    > trying to fix it. But since I am new to Java, when to use what is

    confusing
    > to me.
    >
    > I have a class called PdfDocWriter. It has a bunch of instance variables

    for
    > things that are needed to create the PDF (pdfOutputFileName, templateName,
    > acribatVersion...) There are 3 methods that I want, writeDocToPrint(),
    > writeDocToImaging() and a private deleteFdF.
    >
    > This is all the info necessary to create the PDF except for the name and
    > value for each field on the acrobat form.
    >
    > I need a structure for an indeterminant number of name / value pairs. When
    > an application (application form for applying for loans) is created, they
    > will be able to use the class I am designing simply by giving the instance
    > vars their info and supplying this name / value pair thing.
    >
    > I am planning to have a class for PdfValues with 2 attributes. Then for

    the
    > ConsolidationApplicationPdf class, I will use a collection of the

    PdfValues.
    > Does this seem a good way to go?
    >


    if the user is passing in name/value pairs you could get them to pass in a
    HashMap. This is like a dictionary/collection in vb, or an associative array
    in perl/php/javascript. For instance they could say

    HashMap params = new HashMap();
    params.put("size", "30");
    params.put("color", "blue");
    generatePdf(params);

    and in your code you could have

    void generatePdf(HashMap params) {
    String color = (String) params.get("color");
    }

    this will only work if your data is suitable for putting into a map. the
    most significant criteria for this is probably that you cannot specify the
    same key twice, otherwise the second will overwrite the first.

    if you don't want a map then you should probably define a simple class for
    an individual element and get them to just pass in a collection of these
    objects.


    > I am sorry if I am asking for basic info or if it seems like I am asking

    you
    > to solve my business problems for me. I wish I had someone around here on
    > whom I could bounce around ideas. But I do not.
    >
    > Thanks
    >
    > S
    >
    >
    Andy Fish, Jun 30, 2004
    #2
    1. Advertising

  3. glunk

    glunk Guest

    "Andy Fish" <> wrote in message
    news:GTAEc.6759$...
    >
    > "glunk" <> wrote in message
    > news:...
    > > Hi. As you can tell from my rapid posts, I am struggling with a design
    > > issue. I am not happy with the design (or lack thereof) which has

    occured
    > in
    > > the subsystem that I am working on. No one has yet tried to use this
    > > subsystem, so I do not have to worry about changing the interface. So I

    am
    > > trying to fix it. But since I am new to Java, when to use what is

    > confusing
    > > to me.
    > >
    > > I have a class called PdfDocWriter. It has a bunch of instance variables

    > for
    > > things that are needed to create the PDF (pdfOutputFileName,

    templateName,
    > > acribatVersion...) There are 3 methods that I want, writeDocToPrint(),
    > > writeDocToImaging() and a private deleteFdF.
    > >
    > > This is all the info necessary to create the PDF except for the name and
    > > value for each field on the acrobat form.
    > >
    > > I need a structure for an indeterminant number of name / value pairs.

    When
    > > an application (application form for applying for loans) is created,

    they
    > > will be able to use the class I am designing simply by giving the

    instance
    > > vars their info and supplying this name / value pair thing.
    > >
    > > I am planning to have a class for PdfValues with 2 attributes. Then for

    > the
    > > ConsolidationApplicationPdf class, I will use a collection of the

    > PdfValues.
    > > Does this seem a good way to go?
    > >

    >
    > if the user is passing in name/value pairs you could get them to pass in a
    > HashMap. This is like a dictionary/collection in vb, or an associative

    array
    > in perl/php/javascript. For instance they could say
    >
    > HashMap params = new HashMap();
    > params.put("size", "30");
    > params.put("color", "blue");
    > generatePdf(params);
    >
    > and in your code you could have
    >
    > void generatePdf(HashMap params) {
    > String color = (String) params.get("color");
    > }
    >
    > this will only work if your data is suitable for putting into a map. the
    > most significant criteria for this is probably that you cannot specify the
    > same key twice, otherwise the second will overwrite the first.
    >
    > if you don't want a map then you should probably define a simple class for
    > an individual element and get them to just pass in a collection of these
    > objects.
    >
    >
    > > I am sorry if I am asking for basic info or if it seems like I am asking

    > you
    > > to solve my business problems for me. I wish I had someone around here

    on
    > > whom I could bounce around ideas. But I do not.
    > >
    > > Thanks
    > >
    > > S
    > >
    > >

    >
    >


    Thanks. Much oblidged.

    S
    glunk, Jun 30, 2004
    #3
  4. glunk wrote:

    > "Andy Fish" <> wrote in message
    > news:GTAEc.6759$...
    >>if the user is passing in name/value pairs you could get them to pass in a
    >>HashMap. This is like a dictionary/collection in vb, or an associative

    >
    > array
    >
    >>in perl/php/javascript. For instance they could say
    >>
    >>HashMap params = new HashMap();
    >>params.put("size", "30");
    >>params.put("color", "blue");
    >>generatePdf(params);
    >>
    >>and in your code you could have
    >>
    >>void generatePdf(HashMap params) {
    >> String color = (String) params.get("color");
    >>}
    >>
    >>this will only work if your data is suitable for putting into a map. the
    >>most significant criteria for this is probably that you cannot specify the
    >>same key twice, otherwise the second will overwrite the first.


    [...]

    A good design principle is to specify types as generically as possible
    so as to place the fewest restrictions on the users of your classes. In
    this case that would mean writing your method to accept the more generic
    Map type instead of the more specific HashMap type. Then users could
    still pass HashMaps to the method but could also pass TreeMaps or
    instances of their own custom Map implementations.


    John Bollinger
    John C. Bollinger, Jun 30, 2004
    #4
  5. glunk wrote:
    > Hi. As you can tell from my rapid posts, I am struggling with a design
    > issue. I am not happy with the design (or lack thereof) which has occured in
    > the subsystem that I am working on. No one has yet tried to use this
    > subsystem, so I do not have to worry about changing the interface. So I am
    > trying to fix it. But since I am new to Java, when to use what is confusing
    > to me.
    >
    > I have a class called PdfDocWriter. It has a bunch of instance variables for
    > things that are needed to create the PDF (pdfOutputFileName, templateName,
    > acribatVersion...) There are 3 methods that I want, writeDocToPrint(),
    > writeDocToImaging() and a private deleteFdF.
    >
    > This is all the info necessary to create the PDF except for the name and
    > value for each field on the acrobat form.
    >
    > I need a structure for an indeterminant number of name / value pairs. When
    > an application (application form for applying for loans) is created, they
    > will be able to use the class I am designing simply by giving the instance
    > vars their info and supplying this name / value pair thing.
    >
    > I am planning to have a class for PdfValues with 2 attributes. Then for the
    > ConsolidationApplicationPdf class, I will use a collection of the PdfValues.
    > Does this seem a good way to go?
    >
    > I am sorry if I am asking for basic info or if it seems like I am asking you
    > to solve my business problems for me. I wish I had someone around here on
    > whom I could bounce around ideas. But I do not.
    >
    > Thanks
    >
    > S
    >
    >


    I get the impression that the name/value pairs will get printed like:
    Name1: Value1
    Name2: Value2

    In which case I think you have a good design there. I would think you want
    to be given a List containing only PdfValue objects.

    A List is an ordered Collection, and you have a choice of implementations -
    ArrayList might be a good one to go for.

    Steve
    Steve Horsley, Jun 30, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shland
    Replies:
    4
    Views:
    571
    shland
    Oct 20, 2003
  2. Biffo

    Best method to accomplish?

    Biffo, Feb 3, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    323
    Biffo
    Feb 3, 2005
  3. Doug Poland
    Replies:
    9
    Views:
    711
    VisionSet
    Sep 27, 2003
  4. Sid
    Replies:
    5
    Views:
    1,065
  5. mutex
    Replies:
    0
    Views:
    199
    mutex
    Jul 27, 2003
Loading...

Share This Page