I'm writing a small CLI program in C# using Object Oriented Programming. I have some Logic Classes as well as interfaces and Controllers to update the User Interface. As far as I unserstand I should add a reference in the UI class for the controller, is this considered common and safe to do?
My Controller uses both the main program Stregsystem as well as the UI StregsystemCLI, If I want to create a reference of the controller I need both an instance of the program and UI, which need a copy from the controller... getting stuck here.
static void Main(string[] args)
{
IStregsystem stregsystem = new Stregsystem();
IStregsystemUI ui = new StregsystemCLI(stregsystem);
StregsystemController controller = new StregsystemController(stregsystem, ui);
controller.StregsystemUI.Start();
}
Stregsystem is the name of the application. My Questions goes as follows: How do I use the functions inside the controller after I started the program in the last line of main?
I don't want to create a new controller opject, since I already have that in main. I want to use a ParseCode() Function in the StregsystemCLI class (UI). Neither do I want a static class, as far as i know, because I work with non-static functions in that function.
public void Start()
{
Console.WriteLine("Welcome");
ParseCommand(); 'StregsystemController.ParseCommand() Dosent Work'
}
The Controller:
class StregsystemController
{
public IStregsystem Stregsystem { get; }
public IStregsystemUI StregsystemUI { get; }
private readonly Dictionary<string, Action<string[]>> adminCommands;
public StregsystemController(IStregsystem stregsystem, IStregsystemUI stregsystemUI)
{
Stregsystem = stregsystem;
StregsystemUI = stregsystemUI;
//Add admin commands
adminCommands = new Dictionary<string, Action<string[]>>();
adminCommands.Add(":q", args => stregsystemUI.Close());
}