I'm following this course here and this is live demo
Please I have few questions to ask you, as I want to confirm that I'm understanding what I'm reading :
1) Why does one set value directly while creating object in below code
Transaction t1 = new Transaction("8877", "6/25/2018");
instead of doing like the below; which doesn't work !!!
Transaction transac1 = new Transaction();
transac1.("1234", "2019/10/03");
2) Is public Transaction() {
and public Transaction(string c, string d)
overloading concept?
3) Is the below a constructor method, using overloading?
public Transaction()
{
tCode = " ";
tDate = " ";
}
4) Why Transaction class doesn't have properties, eventhough I only see two below fields/variable with private access modifiers. whereas I read in OOP book that you must always use properties not to expose fields from outside.
private string tCode;
private string tDate;
public interface ITransactions
{
// interface members
void showTransaction();
}
public class Transaction : ITransactions
{
private string tCode;
private string date;
public Transaction()
{
tCode = " ";
date = " ";
}
public Transaction(string c, string d)
{
tCode = c;
date = d;
}
public void showTransaction()
{
Console.WriteLine("Transaction ID: {0}", tCode);
Console.WriteLine("Date: {0}", date);
}
}
class Tester
{
static void Main(string[] args)
{
Transaction t1 = new Transaction("8877", "6/25/2018");
Transaction t2 = new Transaction("5656", "7/25/2018");
t1.showTransaction();
t2.showTransaction();
Console.ReadKey();
}
}