My intention is to describe the architecture of a tennis court management software with a class diagram, keeping the open-closed principle.
Initially, the software should only provide the following functions:
CourtOfAWeek(week:int):void
. This function outputs all tennis courts in the console.CourtOfADay(day:int):void
. This function outputs all tennis courts of a day in the console.
It should now be possible to add new functionality to the software at any time without having to change the existing software.
My solution concept is to apply the strategy pattern. Each functionality inherits from the abstract class AbstractFunction. I would also include all functions as a list in the Tennis_Center class. (see the class diagram and the code).
AbstractFunction:
abstract class AbstractFunction{
}
GetCourtByDayClass:
class GetCourtByDayClass:AbstractFunction{
public void GetCourtByDay(int day){
Console.WriteLine("Court 1, Court 2 and Court 3 are free.");
}
}
GetCourtByWeekClass:
class GetCourtByWeekClass:AbstractFunction{
public void GetCourtByWeek(int week){
Console.WriteLine($"On Week {week} Court 5 and 6 are available");
}
}
Tennis_Center:
List<AbstractFunction> functionList=new List<AbstractFunction>();
functionList.Add(new GetCourtByDayClass());
functionList.Add(new GetCourtByWeekClass());
functionList[1].GetCourtByWeek(1);
Console.ReadKey();
Now to my problem: I think I misunderstood or incorrectly implemented the strategy pattern. Now when I call the functions in the Tennis_Center class, I get the error message:
"AbstractFunction" does not contain a definition for "GetCourtByWeek", and no accessible GetCourtByWeek extension method could be found that accepts a first argument of type "AbstractFunction" (possibly a using directive or assembly reference is missing). [Tenniscenter]csharp(CS1061)
Can you give me some advice on which pattern is best for implementing the above situation.