I've been working as an SDET and have a bit of programming experience. I recently started learning C#, transitioning from JS/TS. I get the components—like interfaces, classes, and records—but I'm struggling with understanding when to use each of them. The differences in typing between JS/TS and C# have made this even trickier for me since C# feels much more rigid. It's only been 10 days, and I know I'm still learning, but I also seem to struggle with design patterns like Builder and Factory. I'm hoping someone else has faced this learning curve and can share their insights!
4 Answers
I also find that knowing what to use often becomes clearer as you dive deeper into the problem. Sometimes, simplifying your code for readability is more important than sticking to a strict pattern. Start with the easiest solution, and expand from there as needed.
Don't stress about design patterns in the beginning! Focusing on the fundamentals and mastering object-oriented programming is way more crucial. Patterns can come later when you're more comfortable with the basics.
It’s totally normal to feel unsure about this at first. Keep studying design patterns, but give yourself time to grasp the fundamentals first. You’ll get there!
For me, the typing system plays a big role in deciding when to use different structures in C#. In TypeScript, it's all about structural typing, so if an object matches an interface, it works. But in C#, it's nominally typed, meaning you need to define things more clearly by name.
When you think about interfaces, consider them as behavioral contracts, while classes are the traditional way to bundle methods and properties. Records should mainly be used as data containers. For instance, you might use interfaces when you want to toggle between different implementations, classes for core business logic, and records for representing simple data like database results or API requests.
That makes sense! I like how you broke it down. I've thought of interfaces as contracts too, but I tend to mix up when to use them as opposed to classes.
I agree! It's all about getting comfortable with the concepts first. Once you're solid on the basics, everything seems clearer.