Project design
Design the skeleton of the advanced final mini app.
Project: Command runner
In this 5-lesson project you will build a command runner. Each lesson adds one piece, and by the final lesson you have a working whole. The core: an ICommand interface and command classes that implement it.
The first lesson sets up the skeleton: an ICommand interface (with a string Execute() method), a concrete command HelloCommand (returning "Merhaba"), and a Main that calls it. Later lessons extend this skeleton with async, reflection, and dependency injection.
The command pattern
This project is a lean application of the command pattern. Each action is wrapped in its own class; all implement the same interface. The runner knows only the ICommand interface; it does not know the concrete command. Adding a new command does not break existing code.
The concrete command HelloCommand returns "Merhaba" when Execute() is called. Main creates an instance and prints the result. This tiny start will grow with async and reflection in the next lessons.
Exercise Set up the command skeleton
Define an ICommand interface with a string Execute() method. HelloCommand : ICommand returns "Merhaba" when Execute() is called. In Main, create a HelloCommand instance and print the result via Console.WriteLine(cmd.Execute()).
Show example solution
ICommand { public string Execute() => "Merhaba"; }. In Main: var cmd = new HelloCommand(); Console.WriteLine(cmd.Execute());
Example solution:
using System;
interface ICommand
{
string Execute();
}
class HelloCommand : ICommand
{
public string Execute() => "Merhaba";
}
class Program
{
static void Main()
{
var cmd = new HelloCommand();
Console.WriteLine(cmd.Execute());
}
}
Test yourself
-
What is the core of this project?
- The ICommand interface and command classes
- A database connection
- A web server
- A console menu
Show answer
The ICommand interface and command classes — Correct. The ICommand interface and its implementing classes are the project's core.
-
Complete the interface method
string ____();Show answer
string Execute(); -
Match project terms
- ICommand
- Command contract
- HelloCommand
- First concrete command
- Execute
- Run method
- Main
- Program entry