473,799 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remedial course in OO; part II...

Hope I'm not being a Pain In the A..

However; now I've got a similar issue for which I've seen no work
around...

Module Module1

Public Class BaseRow
Public Overridable Function Speak() As String
Return "BaseRow"
End Function
End Class

Public Class SpecializedRow
Inherits BaseRow
Public Overrides Function Speak() As String
Return "SpecializedRow "
End Function
End Class
Public Class Base1
Public Overridable Function NewRow() As BaseRow
Return New BaseRow
End Function
End Class
Public Class Derived1
Inherits Base1
Public Overrides Function NewRow() As SpecializedRow
Return New SpecializedRow
End Function
End Class
Public Sub main()
Dim b As New Base1
Dim d As New Derived1
Dim either As Base1

Console.WriteLi ne(b.NewRow.Spe ak)
Console.WriteLi ne(d.NewRow.Spe ak)

either = b
Console.WriteLi ne(either.NewRo w.Speak)
either = d
Console.WriteLi ne(either.NewRo w.Speak)
End Sub

End Module
The basic problem is:
Public Function NewRow() As SpecializedRow

in the derived class is being forced as Shadows.. I suppose I
understand why -- the signatures are the same; only diff is return
type (which is not part of a function sig); so Overload is not
approriate... however, the Overrides option is being totally rejected
by VB.Net (causes compile error) because:

Module1.vb(26): 'Public Overrides Function NewRow() As SpecializedRow'
cannot override 'Public Overridable Function NewRow() As BaseRow'
because they differ by their return types.

So, I'm not able to use Overloads or Overrides (also tried both
together) and is being forced to Shadows -- which is totally not what
I want. I want to be able to have a base class which will call the
approriate NewRow depending on the particular instance of the object
(Base or Derived). Maybe what I'm attempting is either:

1. not possible.
2. dumb.
3. or whatever...

Any suggestions?

Thanks
Nov 21 '05 #1
2 1476
Make the return type of Derived1.NewRow be BaseRow, that way the signature
will match the one in the base class and you'll be able to do the override.
Since SpecializedRow derives from BaseRow you'll still be able to create a
new instance of SpecializedRow and return it from the method (see below).
If you do this the code in Main() will work as you desire.

Public Class Derived1
Inherits Base1
Public Overrides Function NewRow() As BaseRow
Return New SpecializedRow
End Function
End Class

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"Gill Bates" <gi********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
Hope I'm not being a Pain In the A..

However; now I've got a similar issue for which I've seen no work
around...

Module Module1

Public Class BaseRow
Public Overridable Function Speak() As String
Return "BaseRow"
End Function
End Class

Public Class SpecializedRow
Inherits BaseRow
Public Overrides Function Speak() As String
Return "SpecializedRow "
End Function
End Class
Public Class Base1
Public Overridable Function NewRow() As BaseRow
Return New BaseRow
End Function
End Class
Public Class Derived1
Inherits Base1
Public Overrides Function NewRow() As SpecializedRow
Return New SpecializedRow
End Function
End Class
Public Sub main()
Dim b As New Base1
Dim d As New Derived1
Dim either As Base1

Console.WriteLi ne(b.NewRow.Spe ak)
Console.WriteLi ne(d.NewRow.Spe ak)

either = b
Console.WriteLi ne(either.NewRo w.Speak)
either = d
Console.WriteLi ne(either.NewRo w.Speak)
End Sub

End Module
The basic problem is:
Public Function NewRow() As SpecializedRow

in the derived class is being forced as Shadows.. I suppose I
understand why -- the signatures are the same; only diff is return
type (which is not part of a function sig); so Overload is not
approriate... however, the Overrides option is being totally rejected
by VB.Net (causes compile error) because:

Module1.vb(26): 'Public Overrides Function NewRow() As SpecializedRow'
cannot override 'Public Overridable Function NewRow() As BaseRow'
because they differ by their return types.

So, I'm not able to use Overloads or Overrides (also tried both
together) and is being forced to Shadows -- which is totally not what
I want. I want to be able to have a base class which will call the
approriate NewRow depending on the particular instance of the object
(Base or Derived). Maybe what I'm attempting is either:

1. not possible.
2. dumb.
3. or whatever...

Any suggestions?

Thanks

Nov 21 '05 #2
Smack. "sound of hand hitting forehead"...

Roger that...

Thanks...
"Rob Windsor [MVP]" <rw******@NO.MO RE.SPAM.bigfoot .com> wrote in message news:<#x******* *******@TK2MSFT NGP12.phx.gbl>. ..
Make the return type of Derived1.NewRow be BaseRow, that way the signature
will match the one in the base class and you'll be able to do the override.
Since SpecializedRow derives from BaseRow you'll still be able to create a
new instance of SpecializedRow and return it from the method (see below).
If you do this the code in Main() will work as you desire.

Public Class Derived1
Inherits Base1
Public Overrides Function NewRow() As BaseRow
Return New SpecializedRow
End Function
End Class

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"Gill Bates" <gi********@hot mail.com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
Hope I'm not being a Pain In the A..

However; now I've got a similar issue for which I've seen no work
around...

Module Module1

Public Class BaseRow
Public Overridable Function Speak() As String
Return "BaseRow"
End Function
End Class

Public Class SpecializedRow
Inherits BaseRow
Public Overrides Function Speak() As String
Return "SpecializedRow "
End Function
End Class
Public Class Base1
Public Overridable Function NewRow() As BaseRow
Return New BaseRow
End Function
End Class
Public Class Derived1
Inherits Base1
Public Overrides Function NewRow() As SpecializedRow
Return New SpecializedRow
End Function
End Class
Public Sub main()
Dim b As New Base1
Dim d As New Derived1
Dim either As Base1

Console.WriteLi ne(b.NewRow.Spe ak)
Console.WriteLi ne(d.NewRow.Spe ak)

either = b
Console.WriteLi ne(either.NewRo w.Speak)
either = d
Console.WriteLi ne(either.NewRo w.Speak)
End Sub

End Module
The basic problem is:
Public Function NewRow() As SpecializedRow

in the derived class is being forced as Shadows.. I suppose I
understand why -- the signatures are the same; only diff is return
type (which is not part of a function sig); so Overload is not
approriate... however, the Overrides option is being totally rejected
by VB.Net (causes compile error) because:

Module1.vb(26): 'Public Overrides Function NewRow() As SpecializedRow'
cannot override 'Public Overridable Function NewRow() As BaseRow'
because they differ by their return types.

So, I'm not able to use Overloads or Overrides (also tried both
together) and is being forced to Shadows -- which is totally not what
I want. I want to be able to have a base class which will call the
approriate NewRow depending on the particular instance of the object
(Base or Derived). Maybe what I'm attempting is either:

1. not possible.
2. dumb.
3. or whatever...

Any suggestions?

Thanks

Nov 21 '05 #3

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

Similar topics

5
2294
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...
8
1894
by: sikka noel | last post by:
Hi guyz, I rencenly finished by college book on c++. I have done data structures & operating systems as well. I thought that at this point i know C++ completely. However when I go on internet and look for source codes of C++. They have all these wierd LPCSTR unsigned signed dword and all that lingo that i never studied in my college course. and it makes me feel very weak in C++, even though i can write any project in my c++ book very...
1
2611
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
5
2272
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?
5
1066
by: Gill Bates | last post by:
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
6
1308
by: dndfan | last post by:
Hello, everyone! I am a Python enthusiast, also trying to learn basic Linux skills in order to rid myself of the Windows plague (off-topic rant). I was considering doing a Battleships game that runs in text mode and has the capacity to connect players via networking. Trouble is I have minimal experience in networking, let alone in Python's methods for data exchange. I am looking for a quick-n-dirty approach, upon which I can certainly...
2
3468
by: tmarin7 | last post by:
Does anybody know what book SUN uses to teach the following course: Java Programming Language (SL-275) ? I am trying to become certified for: Sun Certified Programmer for Java 2 Platform 5.0. For those that have become certified, is the exam difficult? Also, if you are interested in selling the book please let me know.
1
1328
by: blangela | last post by:
I am currently teaching 2 part-time (one evening per week) C++ courses using the Deitel & Deitel "C++ How To Program" text. Each course is 13 weeks in length, including time for labs and exams. In earlier posts to this usenet site, people have recommended that I switch texts to "Accelerated C++" by Koenig and Moo. I have just recently received a desk copy of the text from the publisher and I do believe that the approach taken by the...
6
3478
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
9544
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
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
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,...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
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
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.