In the SimpleApp tutorial, the author puts all of his code inside one class file. Causing the rain and the bucket to be within it.
I tried just taking the code and putting it into another class but then I would have duplicate methods in my code, and logically it would be incorrect. For example, I cannot have two create methods in a game.
How would I take the rain or the bucket from the tutorial and put it into a different class?
It’s very simple: you could benifit from OOP style coding:
Just use a super class
RainBucketthat has all the methods in it with minimal code with each method.Extend the other two classes from this super class and override in it the methods that your class wants to use, this way you would be acomplishing the following OOP rules:
Inheritence: when you derive from the super class two other objects:
class Bucket extends RainBucket {class Rain extends RainBucket {polymorphism: you can declare two objects from the same super class
but by assigning to the two different derived classes as values like
this:
RainBucket bucket = new Bucket()andRainBucket rain = new Rain()