473,811 Members | 4,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remedial course in OO...

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

I would have expected, or hoped, that
Console.WriteLi ne(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.WriteLi ne(Dee(d))
Console.WriteLi ne(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 1066
"Gill Bates" <gi********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLi ne(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********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLi ne(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.WriteLi ne(Dee(d))
Console.WriteLi ne(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********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLi ne(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.WriteLi ne(Dee(d))
Console.WriteLi ne(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********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLi ne(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.WriteLi ne(Dee(d))
Console.WriteLi ne(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******* *******@TK2MSFT NGP09.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********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
I suppose I need an OO-101 remedial course, or something.

I would have expected, or hoped, that
Console.WriteLi ne(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.WriteLi ne(Dee(d))
Console.WriteLi ne(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
2295
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 people can order products. Our teacher has told us that we need to use Mysql and PHP. I also want to use a login. I want the site to work like: When the user isnt logged in they cant make any orders but when they are the can then proceed further on...
1
2612
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 topics to include in a course on object-orientation that I'm going to conduct. (I will later summarize all the replies and discussion, for the
1
1354
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 where this sort of course would be running in UK. Could anyone advice where I can find one in UK? I am particularly interested in learning OOP and ADO. Ideally it would be in a group with a good tutor(s). Thank you
2
1788
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
2275
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 universities seem to teach this class. I tried taking one but just found it too boring and irrelevant for what I was doing. What are your thoughts?
2
1353
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 experience getting the job. I currently have no experience in an IT role. So I have decided to take a course to gain a professional qualification. I have already self funded a course in Oracle Database Fundamentals 10g which I see now was a mistake...
1
1339
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 is currently doing embedded microprocessor system development. To get her employer to pay tuition for a Master's degree - MSEE/MSET - she needs to find a transferrable course in Visual C++ which benefits the employer immediately. (The MSET...
6
3479
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 expect criticism. But: 1. Most of my students are using WinXP. 2. VJ#.Net Express is free and has an outstanding GUI. 3. Code written in VJ#, via the Mono Project could always be ported to other platforms. 4. Java compiler source seems close to...
0
1583
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 each course number, so that the user can populate that course page with data from a previous course. My question is: once the data from the previous course is populating the current course page (after being selected from the aforementioned...
0
9724
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10394
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10127
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.