J
Joe Cool
I have never had any formal training in Object Oriented Programming, I
have had to learn it by studying other people's code. I think I have a
pretty good understanding of it now, but I still occasionally see
something that has me curious.
There are two basic ways to initialize class properties to working
values.
One way is to:
public class myClass
{
public string aString { get; set; }
public myClass(string astring)
{
this.aString = astring;
}
}
later in some other class:
myClass myclass = new myClass("value to set");
Alternatively, there is:
public class myClass
{
public string aString { get; set; }
}
later:
myClass myclass = new myClass();
myclass.aString = "value to set";
Either way works just fine. What I am wondering, which is the "right"
way according to the definition of OOP? Or is there even a "right"
way?
Or is it just a matter of personal preference?
have had to learn it by studying other people's code. I think I have a
pretty good understanding of it now, but I still occasionally see
something that has me curious.
There are two basic ways to initialize class properties to working
values.
One way is to:
public class myClass
{
public string aString { get; set; }
public myClass(string astring)
{
this.aString = astring;
}
}
later in some other class:
myClass myclass = new myClass("value to set");
Alternatively, there is:
public class myClass
{
public string aString { get; set; }
}
later:
myClass myclass = new myClass();
myclass.aString = "value to set";
Either way works just fine. What I am wondering, which is the "right"
way according to the definition of OOP? Or is there even a "right"
way?
Or is it just a matter of personal preference?