Constructor with identical signature

  • Thread starter Thread starter Sune Hansen
  • Start date Start date
S

Sune Hansen

Hi all,

All constructors must have different signatures, but sometimes come upon a
situation where I would like to create to constructors with the same
signature - i.e.:

Public Sub New(integer1 as Integer)
End Sub

Public Sub New(integer2 as Integer)
End Sub

I guess this is a situation a lot of developers knows and I was wondering
what everone else does in such a situation and if there is some kind of best
practice that one should use?

Regrads,
Sune
 
Sune Hansen
what is the need of such task ? how it is possible to execute the
constructors in that class. i can't under stand u'r point

pronojit
 
Sune Hansen said:
All constructors must have different signatures, but sometimes come upon a
situation where I would like to create to constructors with the same
signature - i.e.:

Public Sub New(integer1 as Integer)
End Sub

Public Sub New(integer2 as Integer)
End Sub

I guess this is a situation a lot of developers knows and I was wondering
what everone else does in such a situation and if there is some kind of best
practice that one should use?

It's not something I've ever wanted - how would you distinguish between
the two cases?

If you want two different methods which both create instances using the
same *type* of data but with different semantics, consider factory
methods, where you can use the *name* to distinguish them.
 
Hi, I think the signature means unique...

Anyway, why don't you just make it unique. I migth add additional parameter
to distinguish it. Like:
Public Sub New (integerX as Integer, booleanX as Boolean)

If a Boolean is not enough, you can try another integer then do the
different actual object creation inside the constructor. It hurts the object
concept but it works.

Jason Hsu
 
Sune,
In addition to the other comments consider having both integers as
parameters to the constructor. Such as you always have to give one if you
want the other.

Public Sub New(integer1 as Integer)
End Sub

Public Sub New(integer1 as Integer, integer2 as Integer)
End Sub

You always have to give integer1, sometimes you can give integer2 also.

Hope this helps
Jay
 
Back
Top