Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP - .NET blog
Message
 
To
04/05/2009 11:25:28
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
01397536
Message ID:
01397829
Views:
117
>>>So the code must be written... you only get some help in writing it. I'm still quite happy with three line subclassing, like
>>>
>>>define class myJunk as oldJunk of junk.prg
>>>someproperty="nondefault value"
>>>enddefine
>>>
>>>Laconica brevitas, eh? :)
>>
>>
>>I'm just a .Net rookie, but I think in C# the same thing is just as easy. Still just 3 lines of actual code and just as easy to read. The typical formatting of the curly braces you see most folks using simply spreads it all out into a beautiful piece of C# poetry:
>>
>>
>>public class myJunk : oldJunk
>>{
>> public myJunk()
>> {
>>   someproperty = "nondefault value";
>> }
>>}
>>
>>
>>
>>If you like it tighter and ugly, I'm pretty sure you can go with:
>>
>>
>>public class myJunk : oldJunk
>>{
>> public myJunk() {someproperty = "nondefault value";}
>>}
>>
>
>Not the same at all. My example had zero lines of method code.
>
>BTW, does the parent constructor code run or not? How does one control that?

This post goes into details about how constructors work in .NET:

http://www.yoda.arachsys.com/csharp/constructors.html

Parameterless constructors are always run. If you had class A and Class B inherited from A and Class C inherited from B, the constructors would be run in A, then B, then C. the : base() syntax isn't needed.

If you're just subclassing and don't mind using a field/member instead of property to add your new "property",
public class NewSubclass : OldSubclass
{
   public string someProperty = "New Value";
}
If you wanted to override the default value (that is, someProperty exists in OldSubclass), you would have to do it in the constructor. Behind the scenes the .NET compiler implements default values via the parameterless constructor (if you don't create one, .NET will automatically it for you). Basically that means the above code gets translated into something like:
public class NewSubclass : OldSubclass
{
   public string someProperty;
   public NewSubclass()
   {
      this.someProperty = "New Value";
   }
}
re: "My example had zero lines of method code" - I'm not sure why that's a big deal. Yes, it's different than VFP. But is that really a big surprise? .NET isn't VFP and VFP isn't .NET. They're different languages and have different semantics around how things are done.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform