Hey reddit, been searching all over SO for answers but couldn’t find any solutions. I’ve always found myself recycling the same code across 10 different projects with the same layout, design, and demand. So I created a boilerplate to be able to reuse most of my code and save tons of time in the future. The boilerplate is a gRPC server that communicate with microservices hosted on the cloud. I spawn different servers for different activities.

So in every new project that I’m using this boilerplate on will have one custom class that will always have the methods Start() and Stop().
I would like to write my function in such a way,
So my question is, is it possible to pass a completely different class (anonymous/generic?) every time into that function? My goal is to not modify the boilerplate and only import one class file every time I’m starting a new project.

I mean I guess for every new project I can name the new class “CUSTOMCLASS” but I would like the ability to be able to use different class names without modifying the boilerplate.

Thanks for reading, I’m proactively searching searching for answers as well. More or less I just wanted to hear some constructive feedback from the reddit community.

Unless I’m missing something obvious, this is exactly what Interfaces are for. Have your class implement the interface with the Start and Stop methods and change your “Handle” function to accept that interface type as a parameter.

Hmm, I don’t think interfaces is the answer. Unless my understanding of interfacing is wrong. Sorry, I tried explaining it as clear as I could, but CUSTOMCLASS is always changing.

I have a gRPC client that invokes the function HandleProcess() but for the sake of not having to modifying my boilerplate code I need to be able to pass different classes such as PIG, DOG, HORSE in lieu of CUSTOMCLASS.
My boilerplate will not know the type beforehand, it just knows whatever the type may be, it will have Start()or Stop().

Here’s an example to help further explain,
The GetNoise would belong to a base class generated by gRPC.

source