How to overload FillByPrimaryKey


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I have a base form that has a BusinessLayer property. I then call the FillByPrimaryKey method on this BusinessLayer property (which is of course set to some concrete BO).



I have a BO were I've overloaded the FillByPrimaryKey method (marked method in BO with "Overloads"). I thought that this would hide the FillByPrimaryKey method in BusinessLayer, but apparently it doesn't..my overload never gets called from the form, the one in BusinessLayer gets called. I must not be understanding how this should works... Unsure



How do I overload FillByPrimaryKey (or FillByParent, etc) so I can use a generic BusinessLayer (program to the abstract class/base class), but use the overload in a specific BO if needed?
Replies
Peter Denton
Peter Denton
StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)
Group: Forum Members
Posts: 77, Visits: 787
Greg,

I haven't tested my theory, but I suspect that the reason the shadows is not having the effect you want is because the BO in which you have applied it is being accessed not as the "GregSpecialBO" Type that it is but as "BusinessLayer". Therefore where it is being used it doesn't know about all the "GregSpecial" things, only the standard "BusinessLayer" things, which means the standard "FillByPrimaryKey", rather than the special one you've shadowed it with is being used.

Having said that, accessing the BO as a "GregSpecialBO" my introduce all kinds of other complications. And more to the point I could be completely wrong!

Peter

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Peter,



Thanks for the response. Your theory is correct. BigGrin The sample I posted clearly shows this. I was confused about how shadowing (overloading a method with the same signature from a base class) differed from overriding (overriding a method that is marked Overridable in the base class) in VB.NET (I'm not confused about how C# works...just clueless Blink ).



In the case of shadowing, it is as you say. If I access GregSpecialBO, then my overloaded method is available. If I cast GregSpecialBO to BusinessLayer, then I get the base method. This makes sense because it has to handle the situation were I've created a method in my subclass, then, later, the base class adds a method of the same name with the same signature. How would I get to the base class method? The way it is handled allows casting to control which method I use.



On the other hand, overriding an Overridable method actually replaces the method. This means that calling the overriden method in either GregSpecialBO or on GregSpecialBO cast to BusinessLayer always calls the overriden method.



Most of you probably already know this...I guess I'm mostly typing this so I won't ever forget this again! Pinch
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search