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 trialnemmes
749 PointsWhy is the FactBook object considered a variable of the FunFactsActivity class?
It seems to me it would be more appropriate to call the FactBook object a method of the FunFactsActivity class rather than a variable of it.
Doesn't the FactBook object behave more like a method than a variable? It performs an action - it doesn't just hold an attribute or property of the FunFactyActivity class.
1 Answer
Sina Maleki
6,135 PointsHello there, The mentor put all these algorithm inside the FactBook class because of following <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle">Single responsibility principle</a>. if you want to use this algorithm inside the other activity you can not use the method that inside the funfactActivity. mentor separate this behavior to show us how can we follow the "Don't repeat yourslef" rule. Cheers
Nauman Bashir
1,278 PointsNauman Bashir
1,278 PointsI am a beginner, I maybe wrong: Why is the FactBook object considered a variable of the FunFactsActivity class? Donot see things like that, See like this: FunFactsActivity is a class and FactBook is also a class. The flow of android in this application makes FunFactsActivity class the first one to be accessed so we can say it acts as a main class. And in it, we are creating a instance/object of the class called FactBook. We name it mFactBook. It inherets all the characteristics of FactBook but it has a new name called mFactBook. Still it has independent characteristics then the FunFactsActivity class. Just because mFactBook is initiated in the class FunFactActivity, let it loose it's propertirs and become the method of FunFactActivity class. FactBook is not only performing action it is indeed holding it's own variable of type array of data type string.
you are saying : " it doesn't just hold an attribute or property of the FunFactyActivity class." why would it hold anything of FunFactActivity. They are 2 seperate classes.
I hope it answers.