• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

performAnimalEnrichment() Code Examples

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello - Per the OCA Java SE 8 Programmer I Study Guide, on page 145, it states that the performAnimalEnrichment() "method can't be reused" because it is not using the Period class.  I ran both examples and I do not see the difference in the outputs when I ran the code below.  I must be missing something, would someone please explain why the first example on page 145 can't be used?

Thank you in advance for your review and/or help!

 
Marshal
Posts: 24587
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have the book so I can't be certain what you're referring to. But in real life the first method would be better like this:



Perhaps that's what the book is trying to get at?
 
author & internet detective
Posts: 39339
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The comment about reuse is for if you want to change the number of months. If you want to change 1 months to three, you don't have to change the method that takes a Period as a parameter. And that's good reuse.

This feels trivial because everything is in one class. But pretend it wasn't. If another developer/team wrote the method and gave it to you inside a jar file, it wouldn't be so easy to change the method insides.
 
Shannon Sims
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, from a reusability, that makes sense.  Thank you!
 
Shannon Sims
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't thinking in that manner...thought it would update the LocateDate object.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!