Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App with Kotlin Improving Our Code Simple Refactoring: Using a New Class

Sai Krishna Katkam
PLUS
Sai Krishna Katkam
Courses Plus Student 1,946 Points

Random class object is also being created multiple times whenever the user clicks button. Can we not create object once!

The instructor defines factBook class object in the member section for re-usability but whereas Random class object is also being created multiple times as soon as user hits Button each time.

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

Yes, you can refactor the FactBook so it only creates the Random generator once. Go ahead and try it out on your own.