Mitchelln11
Active member
- Joined
- Apr 10, 2020
- Messages
- 39
- Programming Experience
- Beginner
I recently completed an small assessment that reads a CSV sheet, then adds to it. This is a C# console app. I'm still learning, and at this point, I can achieve MVP, but it is lacking in SOLID principles or 4 pillars of OOP.
Here is a working method for retrieving a first name from a user:
However, I need similar functionality when asking for a last name. That makes me believe I should use something like an abstract class/inheritance where I can re-use a method to ask for and save a value.
How would I convert this to an abstract class?
Is this even the right approach?
Any help is appreciated.
I did start with a parent class:
And the separate class inheriting the parent:
Here is a working method for retrieving a first name from a user:
C#:
public string AddFirstName()
{
Console.WriteLine(Environment.NewLine + "Please Type in the client's first name. Then hit enter after.");
enrolled.FirstName = Console.ReadLine().Trim();
return enrolled.FirstName;
}
However, I need similar functionality when asking for a last name. That makes me believe I should use something like an abstract class/inheritance where I can re-use a method to ask for and save a value.
How would I convert this to an abstract class?
Is this even the right approach?
Any help is appreciated.
I did start with a parent class:
C#:
public abstract class GetConsoleInfo
{
public abstract string UserLogInfo();
}
And the separate class inheriting the parent:
C#:
public class GetFirstName : GetConsoleInfo
{
CsvData enrolled = new CsvData();
FirstCharUpper first = new FirstCharUpper();
public string firstNameUpper;
public override string UserLogInfo()
{
Console.WriteLine(Environment.NewLine + "Please Type in the client's last name. Then hit enter after.");
string firstName = Console.ReadLine();
firstNameUpper = first.FirstUpper(firstName.Trim());
enrolled.FirstName = firstNameUpper;
return enrolled.FirstName;
}
}