Inherits question

Y

YYZ

Can anyone explain how to do this, or if not, why I can't do this? <g>

I'm using (VB.Net 2003) and exposed API from a 3rd party -- it's
basically a way to get data out of the system, but not hit the DB
directly (I can't -- proprietary format). They have an object called a
Loan object -- fine and dandy, but to get most of the properties of
that loan, you have to access like this:

LoanVar.Fields("XX45").Value -- which really equates to Loan Amount,
say, but that isn't all that intuitive as you can imagine.

I'd like to Inherit this Loan class and add my own properites, such as
LoanAmount, and then in the property get, I'd just return
_Loan.Fields("XX45").Value...you know what I mean.

However, I'm hitting problems.

Public Class clsLoanFriendly
Inherits Loans.Loan
End Class

Tells me that clsLoanFriendly must declare a Sub New because its base
class does not have an accessible Sub New that can be called with no
arguments.

Okay, well, fine -- I need to actually have a real loan object to work
with anyway, so I'll make my constructor take a loan object as a
parameter. Added this to the above class:

Public Sub New(ByVal _Loan As Loans.Loan)
End Sub

Now it tells me that the first line in New must be Mybase.New() or
MyClass.New(). Then I get this error:

'Loans.Loan.Private Sub New(session As Session, dataMgr As j)' is not
accessible in this context because it is 'Private'.

Well, I have a session object, but I don't have a dataMgr object,
because that is hidden, not to mention that the entire New sub is
hidden from me.

How can I create an instance of my object and just USE an existing
object, but have my object inherit that other one? That is so
confusing.

Is the answer that I can't, but I can create an object that doesn't
inherit the Loan class, but basically duplicates its properties, and
has a Loan proerty itself that it will use to get all that data? Did
that make sense?

Matt
 
C

Chris Dunaway

I think in your case, there is no need to inherit the existing class,
just make a wrapper around it. Your class would just contain an
instance of the Loans.Loan object:

Public Class clsLoanFriendly
Private _Loan As New Loans.Loan

Public Property LoanAmount As Decimal 'whatever
Get
Return _Load..Fields("XX45").Value
End Get
End Property

End Class
 
Y

YYZ

Thanks -- I think I see why. I didn't want to have to re-produce the
same properties the loan object already has, but I guess I can without
too much trouble.

Thanks

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top