Domanda

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?

È stato utile?

Soluzione

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() {}
}

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top