troubleshooting Question

C# SOLID and best practices

Avatar of Misha
MishaFlag for Russian Federation asked on
Programming.NET Programming* Best PracticeC#
6 Comments2 Solutions37 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
{
       
}

Open in new window


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

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

Open in new window


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

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

Open in new window


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());
       }
    }
}

Open in new window


In real case there is complex logic in method  ToString. And some other objects are using in method ToString()
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
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 2 Answers 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