Oriented-object approach on how to control different classes cleanly I'm currently creating a client/server application (using Java) and I want to make it fully controllable by an input stream (currently the console). At the moment only one class have to be controlled, but I want my code to stay easy to develop.

I found a solution but I think I can do better, so that's why I post this message: I want your advices on my method now and how I could improve it or how should it better be.

Here's my solution: 

I created an interface CommandControllable like:

import java.util.ArrayList;

public interface CommandControllable
{
    public void execute(Command command);
    public void addCommandManager(CommandManager commandManager);
    public ArrayList&lt;CommandManager&gt; getCommandManagers();
}


A class Command like

public class Command
{
    protected String request;

    public Command(String request)
    {
        this.request = request;
    }

    public String ToString()
    {
        return this.request;
    }
}


A class CommandManager

import java.io.InputStream;
import java.util.Scanner;

public class CommandManager implements Runnable
{
    protected Scanner reader;
    protected CommandControllable toControl;
    protected boolean running = false;

    public CommandManager(InputStream stream)
    {
        this.reader = new Scanner(stream);
    }

    @Override
    public void run()
    {
        this.running = true;
        while(this.running)
            {
                if(this.reader.hasNextLine())
                    {
                        Command c = new Command(this.reader.nextLine());
                        this.toControl.execute(c);
                    }
            }
    }

    public void setControllable(CommandControllable toControl)
    {
        this.toControl = toControl;
    }

    public void stop()
    {
        this.running = false;
    }
}


If I want a class to be controllable I write something like:

public class Server implements CommandControllable
{
    protected ArrayList&lt;CommandManager&gt; commandManagers = new ArrayList&lt;CommandManager&gt;();

    public Server()
    {

    }

    public void stop()
    {
        System.out.println("Server stopped");
    }

    @Override
    public synchronized void execute(Command command)
    {
        switch(command.ToString())
        {
            case "quit":
                stop();
                break;
            default:
                System.out.println("Unrecognized command");
                break;
        }
    }

    @Override
    public void addCommandManager(CommandManager commandManager)
    {
        commandManager.setControllable(this);
        this.commandManagers.add(commandManager);
    }

    @Override
    public ArrayList&lt;CommandManager&gt; getCommandManagers()
    {
        return this.commandManagers;
    }
}


And

public static void main(String[] args)
{
    Server s = new Server();
    CommandManager manager = new CommandManager(System.in);
    s.addCommandManager(manager)

    Thread t_manager = new Thread(manager);
    t_manager.start();
}


Any advices on the current solution and how to improve it?
CommandManager referes to a CommandControllable, and CommandControllable refers to a set of CommandManagers. Who controls who? Such loops in dependency graph should be avoided.

Then, think if the Actor model can be applied in your case.