This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Java Fundamentals: Object-oriented Design by Allen Holub

 
Ranch Hand
Posts: 123
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am following the course as in title. The course is available on PluralSight, free April trial.

This is an example he's providing with on 'not to use getters and setters and decoupling'.

As I am a noob, I barely understand what he's trying to do.
Can we discuss this?
Maybe have a version of the code running?

 
Marshal
Posts: 15565
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would you like to discuss about this code?

When trying to understand some code, the first thing I look for are tests. The tests, if written well, will give you an idea of the purpose/intent of the class under test. It will give you examples of how the class is to be used and other important details like valid vs. invalid input, if it relies on any collaborators to do something, etc.
 
Junilu Lacar
Marshal
Posts: 15565
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As posted, I don't think that test is very well-written. The name, test() doesn't give any clue as to what the purpose of the test is. On further analysis, it looks like it will has the potential to go into an infinite recursive loop and eventually crash with a StackOverflowError. If it doesn't go into an infinite recursion, it will just end without any feedback given as to whether or not the test passed.
 
Marshal
Posts: 69035
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe that was an incomplete version of the class still in development. I agree the MoneyTest class isn't great shakes.
 
Lg Long
Ranch Hand
Posts: 123
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree the example is incomplete.
He might think the person watching his course is smart enough to understand the code.

Since I am not, I was hoping to bring this code to a functional state, with your help to at least get some experience from this example.
 
Campbell Ritchie
Marshal
Posts: 69035
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by giving your classes a toString() method, then you can print the current state of your objects.
 
Lg Long
Ranch Hand
Posts: 123
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Start by giving your classes a toString() method,





Thanks!

What does the op, refers to?

What does dispenseFunds function, should have in the body. I added the test(), but it was a no brainer move.
I think it should do something related to the amount?
 
Junilu Lacar
Marshal
Posts: 15565
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lg Long wrote:What does the op, refers to?


It's not clear what idea "op" was meant to convey. That's the problem with names like that, they don't clearly express their intent. The context is money and I can't think of a word that starts with "op" that is related to money. But looking at the method (which you have misspelled by the way), , isGreaterThan, one name that would make more sense is "other" instead of "op". So you'd have this:

The Currency enum doesn't make sense to me. A currency's conversion rate is a temporal property, meaning it will change over time and it can be quite volatile. Also, not all exchange rates are pegged to the US dollar so you also have to account for the basis of the exchange rate between two specific currencies. In short, having the conversionRateTo() method as a member of the Currency enum seems like a misplaced responsibility to me.

What does dispenseFunds function, should have in the body.


You would know better than us since you're the one taking the course. Maybe you should watch that part of the course and listen more carefully.
 
    Bookmark Topic Watch Topic
  • New Topic