0

I want to keep as many things in separate java files for code readability and for debugging issues.

I have a java class Called Actor. The Actor class is designed to be an object that holds all the players information, but also be used for other things, like monsters, ect.

Another class called Status. This class takes care of all the status ailments and will modify the attributes to the Actor (Example: if they are stunned).

I want this Status Class to be a part of Actor, without nesting the classes. Is this possible?

  • The term to look for is [composition](http://www.journaldev.com/1325/what-is-composition-in-java-java-composition-example) - two classes interact with each other but don't extend from each other. – zapl Jan 18 '14 at 16:33
  • I strongly recommend reading up on Java programming, and starting with more basic aspects. – Miserable Variable Jan 18 '14 at 17:41

2 Answers2

0

Give the Actor a member of type Status:

class Status {
  ...
}

class Actor {
  Status status;
}

You can either have the Actor construct the status object directly in its own constructor, or receive a Status instance as a parameter to the constructor.

0

If you have Status in one file

class Status {
}

And your Actor in another file, all you have to do is have an instance of the Status object inside your Actor class

class Actor {
    Status myStatus = new Status();

    public Actor() {}
}
takendarkk
  • 3,347
  • 8
  • 25
  • 37