Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2007, 12:21 PM
Authorized User
 
Join Date: Apr 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Overload for specialization?

Hi gang,

I have a silly question... silly in that I have been an OO developer for almost 19 years now, and this issue just hit me in VB.NET, and I am not sure if my thinking is correct for the language.

I have an abstract class DataBroker, and I want to force all derived classes to implement some specific functionality. One of those methods is Delete.

Now in the DataBroker abstract class, I write the method template:
Code:
Public MustOverride Function Delete(ByVal aBO as BO) As Boolean
BO is an object that will be passed as an example of what to delete.

In my subclass, PersonDataBroker, I override the function:
Code:
Public Overrides Function Delete(ByVal aPerson as Person) As Boolean
Note that Person IS a subclass of BO.

This causes an error saying that I have not overridden the method, assumedly because the passed types differ.

So, here is the deal... I want to force subclasses to implement this method, but the subs will know what specific BO type they are getting. I need to be able to call functionality on the specific BO type (i.e. Person) in the specialized data broker (i.e. PersonDataBroker).

With me so far?

So, it seems to be that I need to OverLOAD the abstract function... but for some reason that just feels wrong.

Am I missing something here or is this the way to do it?

I was going to use Generics, but that does not seem to fit the bill properly either.

Any help greatly appreciated!

Chris
 
Old May 4th, 2007, 03:00 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

So you cannot use As BO in the overriding declaration and pass it a Person? Does that violate your needs? Does that compile?
 
Old May 7th, 2007, 10:49 AM
Authorized User
 
Join Date: Apr 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian,

I think I did end up using the generic, but I had to discover constraints (especially the New constraint) before it worked.

The solution ended up looking something like:
Code:
Public Function Delete(Of aBO)(ByVal anExample As aBO) As Boolean
No more need to override in subclasses, just pass the type per usual in the function call.

Thanks!

Chris





Similar Threads
Thread Thread Starter Forum Replies Last Post
Webshop - Overload resolution failed silvia23 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 August 3rd, 2008 03:31 AM
Chapter 8 Overload Constructor KMac BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 9 July 13th, 2007 04:22 AM
Unary operator overload and inheritance Jonax C++ Programming 8 February 27th, 2006 08:50 AM
subtraction operator overload arnie6 C++ Programming 0 April 19th, 2005 07:57 AM
can we overload 'as' keyword g_natarajan_mca General .NET 0 August 30th, 2004 07:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.