× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Instantiation question
  • From: "Clapham, Paul" <pclapham@xxxxxxxxxxxxx>
  • Date: Wed, 7 Feb 2001 10:21:12 -0800

Don't know how it would help you, but let me give you an example of how it
would help me.

The company I work for sells products across much of North America.  As a
result, we have many many commodity taxes that we have to collect and
record.  In some cases there is more than one tax involved in the sale of an
individual item.  And if we ship from one state to another, we have to
report to both states.  So, first I have this awful unreadable RPG program
that identifies the applicable taxes, and then there's another complex bit
of code that calculates the amounts of the applicable taxes.  It's all
table-driven, but it's still awful.

Being RPG, my program has to preallocate an array to store the tax ID
numbers in, and it has to have only one piece of code to calculate the tax.
As a result, I allocate an array with 10 entries, because we haven't come
close to that yet.  And the tax calculation code has lots of logic that says
"if the tax is calculated as %, then..., else if..., then..." in many
places.

Here's the object-oriented way of doing it:  I define a TaxCalc class, that
will have a method called "getValue()".  [It's actually more complicated
than that, but I simplify to get a readable example.]  Then my program needs
to get a list of TaxCalc objects, one for each object, and call their
getValue() methods to get the tax amounts.  A list, in RPG, pretty much has
to be an array, but in Java there are other data structures that are more
flexible.

Now when you look at commodity taxes, you'll find there are a few standard
ways of calculating the tax.  One is as a percentage of the transaction
cost, another is as a fixed amount per unit, and there are a few others.  So
I'd define a TaxCalcByPercent class, a TaxCalcByUnit class, and so on, that
extend TaxCalc.  TaxCalcByPercent's getValue() method would simply return a
percentage calculation, and so on for the other classes.  So my list of
TaxClass objects could include objects of any of these subclasses, and when
I call one for getValue(), the appropriate calculation is made
automatically.  Then if somebody dreams up a new tax calculation that
doesn't fit with anything we've had before, I simply create a new class that
extends TaxCalc and provides the correct calculation.  Whereas in RPG, I'd
have to go into the awful Tax Calculation Black Box program and put the new
code in with the old code -- and then I'd have to test everything to make
sure I didn't break one of the existing taxes.

I'm sure this hasn't made you say "AHA!", but hopefully it helps.

PC2

-----Original Message-----
From: Bartell, Aaron L. (TC) [mailto:ALBartell@taylorcorp.com]
Sent: February 7, 2001 08:39
To: 'JAVA400-L@midrange.com'
Subject: RE: Instantiation question


I appreciate everyone's explanations and now I understand how it works, but
where would I use this in a real world application?  I am trying to break my
mental barrier from RPG to Java.  In RPG I would CHAIN or READ from a file
and the I specs that were created on the compile would hold the info for
each of the fields of that file.

I am just lost as to how this will help me, but then again I don't think
that I am thinking in an object oriented manner.  Please help.

Aaron Bartell

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.