I found this code snippet in the Sierra and Bates java certification book. From what I can garner from the book, it is loose because the first class, DoTaxes, has knowledge of a member of the second class, SalesTaxRates (salesRate)--I'm sure that's not right. Or is it because the second class has called the doColorado() method of the DoTaxes class? Which brings me to my other question: Since both classes are using instances, variables and methods from each other, what gets called or processed first? It's like going around in circles.
this piece of code is the opposite of loose coupling -> tight coupling...
the two classes are highly dependent from each other (they share instance variables and methods).
In good code it is easy to just change an implementation of something with something else without breaking other code. Now imagine you want to implement a new version of SalesTaxRates. You will have to reimplement DoTaxes as well. And now, think of 5000 classes ;-)
JDBCSupport - An easy to use, light-weight JDBC framework -
Joined: Mar 24, 2008
Oh yes, I meant tight coupling and said loose in error. Thank you.
But how about my other question, the one about which process occurs first, "salesRate = new DoTaxes().doColorado();" or "SalesTaxRates str = new SalesTaxRates();" or is this all part of the tight coupling trauma? I mean, if the classes access members from each other, what happens first?
For instance, when class SalesTaxRates creates the salesRate float variable, has the DoTaxes() class been processed yet? Because if it hasn't, then how would the salesRate even be created, since it comes from "new DoTaxes().doColorado()"? And if it has, then how did it create the SalesTaxRates object str without first having the second object? This circuitous thinking is driving me batty!
I think understanding this logic would go a long way towards my Java education.
One last question: Why is there a "new" in front of DoTaxes().doColorado() if salesRates is a float variable?
Thanks for any help at all.
Joined: Feb 23, 2009
There is no problem here.
At the time getSalesRate get's called and calls doColorado which then accesses salesRate, this variable will simply be null since it has not been initialized.
Your doColorado method should return a value, by the way.
Nice to see you again, Vonique. A method called something like "doColorado" looks very suspect to me. It should be something like "foo(colorado)".
Joined: Mar 24, 2008
Nice to come back here, Campbell. I always get good answers----so interesting. I finally decided to enrol in a real Java class at the community college, starting in two weeks. Studying on my own is too confusing. It's been great having this site as a resource, though.
I'm sure I will be back, as usual. Thanks for all the help in the past, Campbell. And thanks Sebastian for your explanation. Sometimes I know something but need another explanation to confirm it.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com