Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > design question about collections, or how to accomplish

Reply
Thread Tools

design question about collections, or how to accomplish

 
 
glunk
Guest
Posts: n/a
 
      06-30-2004
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


 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      06-30-2004

"glunk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
glunk
Guest
Posts: n/a
 
      06-30-2004

"Andy Fish" <(E-Mail Removed)> wrote in message
news:GTAEc.6759$(E-Mail Removed)...
>
> "glunk" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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


 
Reply With Quote
 
John C. Bollinger
Guest
Posts: n/a
 
      06-30-2004
glunk wrote:

> "Andy Fish" <(E-Mail Removed)> wrote in message
> news:GTAEc.6759$(E-Mail Removed)...
>>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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Steve Horsley
Guest
Posts: n/a
 
      06-30-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best method to accomplish? Biffo ASP .Net 0 02-03-2005 06:10 PM
XML: Better way to accomplish this? flamesrock Python 2 01-04-2005 12:08 AM
what's the difference between delete ptr and ptr=0 -dont they accomplish the same Sid C++ 5 07-29-2004 03:42 AM
what could you accomplish with a degree? Augustine Kaplan Python 0 05-19-2004 11:53 AM
Newbie question: How to accomplish an HTTP Post in ASP.NET shland ASP .Net 4 10-20-2003 09:46 PM



Advertisments