473,413 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Remedial course in OO...

I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLine(Bee(d))
would have printed "Derived1"; not "Base1"..

I'm sure this is an easy thing to accomplish?
Module Module1

Public Class Base1
Public ReadOnly Property Result() As String
Get
Return "Base1"
End Get
End Property
End Class
Public Class Derived1
Inherits Base1
Public Shadows ReadOnly Property Result() As String
Get
Return "Derived1"
End Get
End Property
End Class
Public Sub main()
Dim d As New Derived1

Console.WriteLine(Dee(d))
Console.WriteLine(Bee(d))
End Sub
Public Function Dee(ByVal d As Derived1) As String
Return d.Result
End Function
Public Function Bee(ByVal b As Base1) As String
Return b.Result
End Function

End Module
Nov 20 '05 #1
5 1046
"Gill Bates" <gi********@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLine(Bee(d))
would have printed "Derived1"; not "Base1"..

I'm sure this is an easy thing to accomplish?


That looks right to me. d is being passed into Bee as type Base1, so the
shadow implementation is never called (or referred to). Option Strict On
can help you spot these scenarios sometimes.

The variable will always need to be of type Derived1 in order for the shadow
to work. The parameter for Bee basically un-does the shadow, and sees b
only as Base1. Do you see it now?

Best Regards,

Andy
Nov 20 '05 #2
I think you are confusing Overrides with Shadows. If you want Bee(d) to
return "Base1" then must use Overrides not Shadows it. Of course the
original property must be Overridable.

Fred
"Gill Bates" <gi********@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLine(Bee(d))
would have printed "Derived1"; not "Base1"..

I'm sure this is an easy thing to accomplish?
Module Module1

Public Class Base1
Public ReadOnly Property Result() As String
Get
Return "Base1"
End Get
End Property
End Class
Public Class Derived1
Inherits Base1
Public Shadows ReadOnly Property Result() As String
Get
Return "Derived1"
End Get
End Property
End Class
Public Sub main()
Dim d As New Derived1

Console.WriteLine(Dee(d))
Console.WriteLine(Bee(d))
End Sub
Public Function Dee(ByVal d As Derived1) As String
Return d.Result
End Function
Public Function Bee(ByVal b As Base1) As String
Return b.Result
End Function

End Module

Nov 20 '05 #3
Gill,
The others have answered the problem.

If you want a good Intro/How To OO book I would recommend Robin A.
Reynolds-Haertle's book "OOP with Microsoft Visual Basic .NET and Microsoft
Visual C# .NET - Step by Step" from MS Press.

Hope this helps
Jay

"Gill Bates" <gi********@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLine(Bee(d))
would have printed "Derived1"; not "Base1"..

I'm sure this is an easy thing to accomplish?
Module Module1

Public Class Base1
Public ReadOnly Property Result() As String
Get
Return "Base1"
End Get
End Property
End Class
Public Class Derived1
Inherits Base1
Public Shadows ReadOnly Property Result() As String
Get
Return "Derived1"
End Get
End Property
End Class
Public Sub main()
Dim d As New Derived1

Console.WriteLine(Dee(d))
Console.WriteLine(Bee(d))
End Sub
Public Function Dee(ByVal d As Derived1) As String
Return d.Result
End Function
Public Function Bee(ByVal b As Base1) As String
Return b.Result
End Function

End Module

Nov 20 '05 #4
Avoid Shadows. It is meant to be used when someone changes a class you are
inheriting from and you don't want your code to break.

--
Jonathan Allen
"Gill Bates" <gi********@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLine(Bee(d))
would have printed "Derived1"; not "Base1"..

I'm sure this is an easy thing to accomplish?
Module Module1

Public Class Base1
Public ReadOnly Property Result() As String
Get
Return "Base1"
End Get
End Property
End Class
Public Class Derived1
Inherits Base1
Public Shadows ReadOnly Property Result() As String
Get
Return "Derived1"
End Get
End Property
End Class
Public Sub main()
Dim d As New Derived1

Console.WriteLine(Dee(d))
Console.WriteLine(Bee(d))
End Sub
Public Function Dee(ByVal d As Derived1) As String
Return d.Result
End Function
Public Function Bee(ByVal b As Base1) As String
Return b.Result
End Function

End Module

Nov 20 '05 #5
All excellent advice. Thanks... got it working now with all the
helpful suggestions...
"Jonathan Allen" <X@X> wrote in message news:<e9**************@TK2MSFTNGP09.phx.gbl>...
Avoid Shadows. It is meant to be used when someone changes a class you are
inheriting from and you don't want your code to break.

--
Jonathan Allen
"Gill Bates" <gi********@hotmail.com> wrote in message
news:8e**************************@posting.google.c om...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLine(Bee(d))
would have printed "Derived1"; not "Base1"..

I'm sure this is an easy thing to accomplish?
Module Module1

Public Class Base1
Public ReadOnly Property Result() As String
Get
Return "Base1"
End Get
End Property
End Class
Public Class Derived1
Inherits Base1
Public Shadows ReadOnly Property Result() As String
Get
Return "Derived1"
End Get
End Property
End Class
Public Sub main()
Dim d As New Derived1

Console.WriteLine(Dee(d))
Console.WriteLine(Bee(d))
End Sub
Public Function Dee(ByVal d As Derived1) As String
Return d.Result
End Function
Public Function Bee(ByVal b As Base1) As String
Return b.Result
End Function

End Module

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Adrian | last post by:
I am currently trying to do my final piece of coursework for my ICT A-level, Fo r the course work we have to make a web based database or something releated. I have chosen to do a site whjere...
1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
1
by: n2alexan | last post by:
Hi, I live in UK. Could someone give me an advice. I want to take a course in .NET Development. I am familiar with .NET already and the course should not be for complete beginners. I do not know...
2
by: Gil | last post by:
I was looking for a good advanced programming course covering Object Oriented Programming and C++ in Germany. Can anyone recommend a good course? Thank you, Gil
5
by: el_roachmeister | last post by:
For being a good web programmer, is a course on data structures important? It seems php already has built-in functions for what they teach in a data structures course. On the other hand all...
2
by: Mark | last post by:
Hi, I am a recent graduate of Software Engineering and I am struggling to secure a job. I can't even seem to get into a support role or helpdesk position as there always seems to be someone with...
1
by: kalos | last post by:
I'm looking for an online (distance) Visual C++ course that can be taken as transfer credit for a Master's degree in Electrical Engineering/Technology. The student is familiar with C and C+ and...
6
by: Bob Palank | last post by:
I'm considering using VJ# in a first programming course in addition to or in place of JBuilder and the J2SE. Given install problems other students have had, VJ# seems like a nice alternative. I...
0
by: ll | last post by:
I'm currently working with an ASP page that populates rows based on a query for course data by using a DO WHILE NOT EOF loop. An improvement I'm adding is a dropdown populated by query which shows...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.