r/learnprogramming • • 24d ago

Design Patterns

I'm a 5+ year developer who never really studied programming patterns and paradigms. I'm currently tutoring a student in a high-school and I got to thinking about my own programming and design patterns.

When it comes to building an application, in my case one that makes requests, caches the data, and performs some analysis, I'm often considering where it makes the most sense to bind certain functionality and call it from. I'm primarily using an object-oriented paradigm.

Currently I have several threads responsible for calling a number of asynchronous tasks that should:

  • Make a web request (retrieving data from an API)
    • Potentially make follow up requests
  • Cache the response data
  • Analyze/Display the most recently cached data

Right now, I have the cache responsible for calling out to the API so that it can retrieve its data to store, but I'm questioning this from an architectural standpoint. It almost seems to me as if the thread or task should have a series of statements more akin to functional programming to control flow.

How would you approach this or recommend a design?

2 Upvotes

7 comments sorted by

View all comments

1

u/Pale-Preparation-354 20d ago

The main thing is keeping each part responsible for one job. The API client handles requests, the cache deals with storing and retrieving data, and a separate service coordinates the whole flow. That also makes testing individual pieces much easier.

For anything that needs to generate reports or export results as PDFs, tools like IronPDF can come in handy alongside libraries for handling API calls and caching. It lets you generate PDFs from HTML in .NET without having to build the rendering part yourself. I'd focus on keeping that kind of output functionality separate too, rather than letting the cache or API layer handle it.