troubleshooting Question

C# SOLID and best practices

Avatar of Misha
MishaFlag for Russian Federation asked on
Programming.NET ProgrammingC#* Best Practice
6 Comments1 Solution37 ViewsLast Modified:
Hello!
I need advice for SOLID principles and programming best practices.

I have two classes inherited from one main class. Objects of this classes are in List. I need beautifull solution to print information about this classes

Class Entity
class Entity
{
       
}

Class Person
sealed class Person : Entity
{
       internal FirstName {get; set;}
       internal LastName {get; set;}

       public override string ToString()
        {
            return $"FirstName ={FirstName } LastName  = {LastName } ";
        }
 }

Class Car
sealed class Car: Entity
{
       internal Name {get; set;}
       internal MaxSpeed {get; set;}

       public override string ToString()
        {
            return $"Name ={Name } MaxSpeed = {MaxSpeed } ";
        }
}

Class Writer
sealed class Writer
{
    internal void Write()
    {
        List<Entity> entities= new List<Entity>();
       // add some persons..
      // add some cars...
       StreamWriter writer = new StreamWriter("qwe.txt");
       foreach (Entity e in entities)
       {
            writer.WriteLine(e.ToString());
       }
    }
}

In real case there is complex logic in method  ToString. And some other objects are using in method ToString()
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros