Search code examples
javaarchitecturetext-based

Creation of an Object that is inside of another object


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?


Solution

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