MaggyD
Explore posts from serversIdiomatic C# Data Objects with Immutable Collections?
Hello, I'm trying to understand the best way to define a class that holds collection of some data that is completely immutable, yet serializable and deserilazable by System.Text.Json. For instance, I want this class to just represent a JSON document from the front-end application, it can be seen as a form of DTO as some sort. However, after spending 30 minutes online and asking ChatGPT, I feel like I still don't have a clear guide on how to construct a class with collections.
I have tried multiple things in my experience with C#.
Backing fields.
Just making them mutable and ignoring the warnings.
Some combination of the previous two???
Please help.
Thanks,
Maguire
24 replies
Achieving polymorphism for an association
Hi, I'm curious about the nature of run-time/compile-time polymorphism when a parent object is associated with some other object. What I mean by association is that an object keeps that parent class as a reference, i.e., it owns it.
What I'm trying to figure out right now in my application is how can I associate children of the parent in substitution for the parent class, yet some how gain access to child specific attributes and methods.
Is this possible?
Examples:
14 replies