473,385 Members | 1,326 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,385 software developers and data experts.

"Polymorphism" and Interfaces

I have an IRange interface defined as...
Public Interface IRange
Property Min() As Object
Property Max() As Object
End Interface
....and I want to implement that in different kinds of range objects
like IntegerRange, StringRange, WeightRange, CurrencyRange, etc.
But I can't implement the interface using more specific types like
this
Public Class IntegerRange
Implements IRange
Private _max As Integer
Public Property Max() As Integer Implements IRange.Max
Get
Return _max
End Get
Set(ByVal value As Integer)
_max = value
End Set
End Property
....
The error is of course that 'Max' cannot implement 'Max' because there
is no matching property on interface 'IRange'.
I guess part of me feels like this should be allowed since Integers
and anything else I want to make a range object out of are Objects.

In the end I was wanting collections of type-specific range objects
that I could sort, perhaps by implementing IComparable, and display in
a windows control. Should I be trying some other path?
Thanks.

Jul 4 '07 #1
3 1478
How about using generics:

Public Interface IRange(Of t)

Property Max() As t
Property Min() As t

End Interface

Public MustInherit Class RangeBase(Of t)
Implements IRange(Of t)

Private _max As t
Public Property Max() As t Implements IRange(Of t).Max
Get
Return _max
End Get
Set(ByVal value As t)
_max = value
End Set
End Property

Private _min As t
Public Property Min() As t Implements IRange(Of t).Min
Get
Return _min
End Get
Set(ByVal value As t)
_min = value
End Set
End Property
End Class

Public Class IntegerRange
Inherits RangeBase(Of Integer)

End Class

Public Class StringRange
Inherits RangeBase(Of String)

End Class

Hope this helps

Tom

-----Original Message-----
From: di*******@gmail.com [mailto:di*******@gmail.com]
Posted At: 04 July 2007 22:15
Posted To: microsoft.public.dotnet.languages.vb
Conversation: "Polymorphism" and Interfaces
Subject: "Polymorphism" and Interfaces

I have an IRange interface defined as...
Public Interface IRange
Property Min() As Object
Property Max() As Object
End Interface
....and I want to implement that in different kinds of range objects
like IntegerRange, StringRange, WeightRange, CurrencyRange, etc.
But I can't implement the interface using more specific types like
this
Public Class IntegerRange
Implements IRange
Private _max As Integer
Public Property Max() As Integer Implements IRange.Max
Get
Return _max
End Get
Set(ByVal value As Integer)
_max = value
End Set
End Property
....
The error is of course that 'Max' cannot implement 'Max' because there
is no matching property on interface 'IRange'.
I guess part of me feels like this should be allowed since Integers
and anything else I want to make a range object out of are Objects.

In the end I was wanting collections of type-specific range objects
that I could sort, perhaps by implementing IComparable, and display in
a windows control. Should I be trying some other path?
Thanks.

Jul 4 '07 #2
On Jul 4, 4:28 pm, "Tom John" <tdj...@nospam.nospamwrote:
How about using generics:

Public Interface IRange(Of t)

Property Max() As t
Property Min() As t

End Interface

Public MustInherit Class RangeBase(Of t)
Implements IRange(Of t)

Private _max As t
Public Property Max() As t Implements IRange(Of t).Max
Get
Return _max
End Get
Set(ByVal value As t)
_max = value
End Set
End Property

Private _min As t
Public Property Min() As t Implements IRange(Of t).Min
Get
Return _min
End Get
Set(ByVal value As t)
_min = value
End Set
End Property
End Class

Public Class IntegerRange
Inherits RangeBase(Of Integer)

End Class

Public Class StringRange
Inherits RangeBase(Of String)

End Class

Hope this helps

Tom

-----Original Message-----
From: dippyk...@gmail.com [mailto:dippyk...@gmail.com]

Posted At: 04 July 2007 22:15
Posted To: microsoft.public.dotnet.languages.vb
Conversation: "Polymorphism" and Interfaces
Subject: "Polymorphism" and Interfaces

I have an IRange interface defined as...
Public Interface IRange
Property Min() As Object
Property Max() As Object
End Interface
...and I want to implement that in different kinds of range objects
like IntegerRange, StringRange, WeightRange, CurrencyRange, etc.
But I can't implement the interface using more specific types like
this
Public Class IntegerRange
Implements IRange
Private _max As Integer
Public Property Max() As Integer Implements IRange.Max
Get
Return _max
End Get
Set(ByVal value As Integer)
_max = value
End Set
End Property
...
The error is of course that 'Max' cannot implement 'Max' because there
is no matching property on interface 'IRange'.
I guess part of me feels like this should be allowed since Integers
and anything else I want to make a range object out of are Objects.

In the end I was wanting collections of type-specific range objects
that I could sort, perhaps by implementing IComparable, and display in
a windows control. Should I be trying some other path?
Thanks.
Hey, I've got it. I think I can use generics. j/k! Thanks a heap, Tom;
it's perfect!

Jul 4 '07 #3

"di*******@gmail.com" wrote:
Hey, I've got it. I think I can use generics. j/k! Thanks a heap, Tom;
it's perfect!
Good stuff! Generics are pretty cool, more than just strongly typed
collections!

Cheers

Tom
Jul 4 '07 #4

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

Similar topics

24
by: Alf P. Steinbach | last post by:
The eighth chapter (chapter 2.1) of my attempted Correct C++ tutorial is now available, although for now only in Word format -- comments welcome! Use the free & system-independent Open Office...
2
by: Torsten Landschoff | last post by:
Hi there, I am having an interesting C++ problem which I currently am working around but I don't like this so perhaps somebody has a better idea. Basically I am parsing (rather: scanning) a...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
13
by: Fao | last post by:
Hello, I am having some problems with inheritance. The compiler does not not return any error messages, but when I execute the program, it only allows me to enter the number, but nothing else...
7
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see...
7
by: desktop | last post by:
This page: http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html start with the line: "Virtual functions allow polymorphism on a single argument". What does that exactly mean? I guess it...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
5
by: Ronald Raygun | last post by:
If I have the following class heirarchy: class A{ protected $m_type; function type(){return $this->m_type;} } class B extends A{} class C extends B{}
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.