design question about collections, or how to accomplish

G

glunk

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
 
A

Andy Fish

glunk said:
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.
 
G

glunk

Andy Fish said:
occured

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.

Thanks. Much oblidged.

S
 
J

John C. Bollinger

[...]

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
(e-mail address removed)
 
S

Steve Horsley

glunk said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top