D
drg
Hello,
I ran into a little trouble while trying to design some classes for a
Java program. It's going to be a database front end basically, so I
figured I should get the data into the database first, to have
something to work with.
The problem goes like this, It's a management software for my TV repair
shop. So I have to create Service Orders (not worrying about that yet),
and I have to specify the Model number of the device. Later, after I
have fixed this Service Order, I'll have to report which Parts I used
(code, description, etc. as in BC548 - NPN Transistor).
So I have 3 tables: the Spare Parts table, the Models table and the
SparePartsByModel. I want to write a program that can take the listings
my providers send monthly and update the database records. The problem
is I have, so far, two types of listings.
One of the providers sends me an XLS file with about 60000 lines, their
SparePartsByModel table. Great, so I iterate through the list three
times: First to get the models, second to get the parts, and third to
load the data by ID field in the SparePartsByModel table. In the
Service menu, the available parts will be displayed for that particular
model.
But the other provider sends me a plain text file with the model, and
another file with the spare parts list. This spare part list also has
the Model field but only for the first match (that is, if I have a
Spare Part used in 10 Models, I get only the first model. Pretty stupid
design, but well, they've been doing it that way for over 10 years now
so it seems to be Good Enough for them). So in the Service menu I'd
have to remove the "show parts available for this model only" filter.
The problem is, how can I make a pretty implementation for this?
I thought of something like this:
ListProcessor
SparePartsListProcessor extends ListProcessor
BrandASparePartsListProcessor extends SparePartsListProcessor
BrandBSparePartsListProcessor extends SparePartsListProcessor
ModelListProcessor extends ListProcessor
BrandAListProcessor extends ModelListProcessor
BrandBListProcessor extends ModelListProcessor
What for? So that I'll give ListProcessor file and it will autodetect
if it's a Brand A list, or a Brand B list, etc. If tomorrow I have a
Brand C, I'll just create the classes for Brand C and so on.
The main problem I have is that I cannot just plug a
BrandCSparePartsListProcessor, I have to notify SparePartsListProcessor
that I have another class to try (I want the program to autodetect the
filetype: BrandAxxxProcessor opens the file and check if it has the
right format and accept it, if not it throws an
InvalidFileSomethingException and the program tries with the next
available processor, until it finds one or it throws a
NoProcessorsFoundException, for example).
But I feel that it's either wrong or unnecessarily complicated. What do
you think?
Best regards, and sorry for the long post
Hernan Freschi
I ran into a little trouble while trying to design some classes for a
Java program. It's going to be a database front end basically, so I
figured I should get the data into the database first, to have
something to work with.
The problem goes like this, It's a management software for my TV repair
shop. So I have to create Service Orders (not worrying about that yet),
and I have to specify the Model number of the device. Later, after I
have fixed this Service Order, I'll have to report which Parts I used
(code, description, etc. as in BC548 - NPN Transistor).
So I have 3 tables: the Spare Parts table, the Models table and the
SparePartsByModel. I want to write a program that can take the listings
my providers send monthly and update the database records. The problem
is I have, so far, two types of listings.
One of the providers sends me an XLS file with about 60000 lines, their
SparePartsByModel table. Great, so I iterate through the list three
times: First to get the models, second to get the parts, and third to
load the data by ID field in the SparePartsByModel table. In the
Service menu, the available parts will be displayed for that particular
model.
But the other provider sends me a plain text file with the model, and
another file with the spare parts list. This spare part list also has
the Model field but only for the first match (that is, if I have a
Spare Part used in 10 Models, I get only the first model. Pretty stupid
design, but well, they've been doing it that way for over 10 years now
so it seems to be Good Enough for them). So in the Service menu I'd
have to remove the "show parts available for this model only" filter.
The problem is, how can I make a pretty implementation for this?
I thought of something like this:
ListProcessor
SparePartsListProcessor extends ListProcessor
BrandASparePartsListProcessor extends SparePartsListProcessor
BrandBSparePartsListProcessor extends SparePartsListProcessor
ModelListProcessor extends ListProcessor
BrandAListProcessor extends ModelListProcessor
BrandBListProcessor extends ModelListProcessor
What for? So that I'll give ListProcessor file and it will autodetect
if it's a Brand A list, or a Brand B list, etc. If tomorrow I have a
Brand C, I'll just create the classes for Brand C and so on.
The main problem I have is that I cannot just plug a
BrandCSparePartsListProcessor, I have to notify SparePartsListProcessor
that I have another class to try (I want the program to autodetect the
filetype: BrandAxxxProcessor opens the file and check if it has the
right format and accept it, if not it throws an
InvalidFileSomethingException and the program tries with the next
available processor, until it finds one or it throws a
NoProcessorsFoundException, for example).
But I feel that it's either wrong or unnecessarily complicated. What do
you think?
Best regards, and sorry for the long post
Hernan Freschi