What I have learned by building .NET Stars -part 2- interfaces

In my latest project, building a robust system using interfaces has been both a fascinating challenge and an enlightening experience. As I embarked on this journey, it quickly became evident how immensely powerful and transformative thinking in terms of interfaces can be.

From the outset, interfacing brought clarity to several core aspects of the application:

  • Data Management: Interfaces provided a transparent view of data structures and their usage within the app.
  • Data Flow: They illuminated how data was accessed and exchanged, simplifying what seemed complex at first glance.
  • Application Flow: Interfaces helped chart out the application’s workflow, providing insights even in its dormant state.

While initially daunting, embracing interfaces has offered immense benefits almost immediately. A notable revelation was how adopting the NullObjectPattern through an interface (you can explore this further at rscg_Interface_to_null_object) enabled me to navigate and visualize my application’s flow effortlessly – a crucial step even when it performs no operations.

One of the quicker wins was leveraging interfaces to support multiple data sources. This flexibility meant that I could seamlessly pull project details from diverse platforms like the .NET Foundation, GitHub repositories such as quozd/awesome-dotnet and thangchung/awesome-dotnet-core by implementing a common interface, IStatsData, and then efficiently saving this consolidated data with a single implementation of IProjectsData.

Our interface designs have opened up a world of possibilities for flexibility and reusability. Consider these interfaces :

[ToNullObject]
public interface IStatsData
{
    //other code
IAsyncEnumerable<IProject> RefreshProjects();
}

[ToNullObject]
public interface IProjectsData
{
    IAsyncEnumerable<IProject> GetProjectsAsync();
    Task<bool> SaveProjects(IProject[] projects);

}

 

With these interfaces, we have the freedom to implement various strategies for acquiring projects from diverse sources such as DotNetFoundation, awesome-dotnet, and awesome-dotnet-core. Moreover, we can centralize the project storage logic with just one implementation of IProjectsData.

The result is a dynamic, versatile application that not only offers rich functionality but also encourages continuous improvement.

Eager to see the fruits of this approach? You can dive into our project live at https://ignatandrei.github.io/dotnetstats/. Additionally, the source code is available for all to explore at http://github.com/ignatandrei/dotnetstats/.