HighTechTalks DotNet Forums  

Re: Interface and struct

VB.net microsoft.public.dotnet.languages.vb


Discuss Re: Interface and struct in the VB.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Bill McCarthy
 
Posts: n/a

Default Re: Interface and struct - 03-31-2004 , 10:54 PM






Hi Bob,

nested classes and structures are only useful for hiding and access to the outer
classes private scoped members. So, you are probably best NOT to nest the
struct.

eg:

Class Foo: Implements IFace
...
End Class

Structure Bar
..
End Sturcture

Interface IFace
..
End Interface

That is, keep them all separate. I have a feeling you are use to structs being
like UDT's in Vb6, which they are in many ways, but they are also more like a
class in many ways too. Most importantly, they do not have to be declared
inside a class, but can be declared just like any class can be.

Bill


"Bob Clegg" <bclegg (AT) clear (DOT) net.nz> wrote

Quote:
Hi Bill,
The class is right.
The interface declaration is more like
Function UpdateBar(myBar as Bar) as boolean

The problem is that it seems to me that Bar should no longer live in Foo,
now that Foo is hiding behind an interface. ( The reason for this is that
Foo is a data class using SQL Server objects and there is soon going to be
an FooBrother that uses Oracle data objects. Only one of the two will be
compiled depending on the installation.) So where to place Bar?
As a number of calling classes want to use Bar it would seem ideal to me to
place it in a module.
But if I do that then the above declaration fails with can't expose a
friend type.
I have a working solution by getting Bar to bunk down in one of the calling
classes, but it seems tacky.
regards
Bob

"Bill McCarthy <no spam>" <bill_mcc @ iprimus.com.au> wrote in message
news:uNBBaCyFEHA.3576 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi Bob,

Do you mean you have :

Class Foo
Public Structure Bar
...
End Structure
End Class

and you want to define an Interface, such as :

Public IFace
Function GetBar() as Foo.Bar
End Interface

If so, Foo must be Public.
Alternatively, don't have Bar nested.



Bill.



"Bob Clegg" <bclegg (AT) clear (DOT) net.nz> wrote in message
news:OoEhpzvFEHA.712 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi,
I have a Data Class that declares a Public struct.
It accepts instances of this struct in some of its function calls.
I now want to put an interface between this class and the calling
classes.

I would like to move the struct out to the module that is housing the
interface.

But when I do this I get a scoping problem.

The interface declaration of any function that is passing one of these
structs complains that it can't expose a friend type publicly.

I have tried putting the struct into the interface and I have also tried
a
public declaration in the module proper and another module.

The only thing that seems to work but doesn't sit comfortably with me is
to
declare it public in one of the calling classes.
Any thoughts?
thanks
Bob










Reply With Quote
  #2  
Old   
Bob Clegg
 
Posts: n/a

Default Re: Interface and struct - 04-01-2004 , 03:10 AM






Hi Bill,
You are on the money.
It is the way I am thinking about it.
Yes. VB6 habits die hard.
The struct can stand alone.
Thanks.
Bob
"Bill McCarthy <no spam>" <bill_mcc @ iprimus.com.au> wrote

Quote:
Hi Bob,

nested classes and structures are only useful for hiding and access to the
outer
classes private scoped members. So, you are probably best NOT to nest the
struct.

eg:

Class Foo: Implements IFace
...
End Class

Structure Bar
..
End Sturcture

Interface IFace
..
End Interface

That is, keep them all separate. I have a feeling you are use to structs
being
like UDT's in Vb6, which they are in many ways, but they are also more
like a
class in many ways too. Most importantly, they do not have to be declared
inside a class, but can be declared just like any class can be.

Bill


"Bob Clegg" <bclegg (AT) clear (DOT) net.nz> wrote in message
news:u3IZmE2FEHA.3880 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi Bill,
The class is right.
The interface declaration is more like
Function UpdateBar(myBar as Bar) as boolean

The problem is that it seems to me that Bar should no longer live in
Foo,
now that Foo is hiding behind an interface. ( The reason for this is
that
Foo is a data class using SQL Server objects and there is soon going to
be
an FooBrother that uses Oracle data objects. Only one of the two will be
compiled depending on the installation.) So where to place Bar?
As a number of calling classes want to use Bar it would seem ideal to me
to
place it in a module.
But if I do that then the above declaration fails with can't expose a
friend type.
I have a working solution by getting Bar to bunk down in one of the
calling
classes, but it seems tacky.
regards
Bob

"Bill McCarthy <no spam>" <bill_mcc @ iprimus.com.au> wrote in
message
news:uNBBaCyFEHA.3576 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi Bob,

Do you mean you have :

Class Foo
Public Structure Bar
...
End Structure
End Class

and you want to define an Interface, such as :

Public IFace
Function GetBar() as Foo.Bar
End Interface

If so, Foo must be Public.
Alternatively, don't have Bar nested.



Bill.



"Bob Clegg" <bclegg (AT) clear (DOT) net.nz> wrote in message
news:OoEhpzvFEHA.712 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi,
I have a Data Class that declares a Public struct.
It accepts instances of this struct in some of its function calls.
I now want to put an interface between this class and the calling
classes.

I would like to move the struct out to the module that is housing
the
interface.

But when I do this I get a scoping problem.

The interface declaration of any function that is passing one of
these
structs complains that it can't expose a friend type publicly.

I have tried putting the struct into the interface and I have also
tried
a
public declaration in the module proper and another module.

The only thing that seems to work but doesn't sit comfortably with
me is
to
declare it public in one of the calling classes.
Any thoughts?
thanks
Bob












Reply With Quote
  #3  
Old   
Bill McCarthy
 
Posts: n/a

Default Re: Interface and struct - 04-01-2004 , 05:55 AM



Thanks Bob.

"Bob Clegg" <bclegg (AT) clear (DOT) net.nz> wrote

Quote:
Hi Bill,
You are on the money.
It is the way I am thinking about it.
Yes. VB6 habits die hard.
The struct can stand alone.
Thanks.
Bob
"Bill McCarthy <no spam>" <bill_mcc @ iprimus.com.au> wrote in message
news:%23ndToY6FEHA.4084 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
Hi Bob,

nested classes and structures are only useful for hiding and access to the
outer
classes private scoped members. So, you are probably best NOT to nest the
struct.

eg:

Class Foo: Implements IFace
...
End Class

Structure Bar
..
End Sturcture

Interface IFace
..
End Interface

That is, keep them all separate. I have a feeling you are use to structs
being
like UDT's in Vb6, which they are in many ways, but they are also more
like a
class in many ways too. Most importantly, they do not have to be declared
inside a class, but can be declared just like any class can be.

Bill


"Bob Clegg" <bclegg (AT) clear (DOT) net.nz> wrote in message
news:u3IZmE2FEHA.3880 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi Bill,
The class is right.
The interface declaration is more like
Function UpdateBar(myBar as Bar) as boolean

The problem is that it seems to me that Bar should no longer live in
Foo,
now that Foo is hiding behind an interface. ( The reason for this is
that
Foo is a data class using SQL Server objects and there is soon going to
be
an FooBrother that uses Oracle data objects. Only one of the two will be
compiled depending on the installation.) So where to place Bar?
As a number of calling classes want to use Bar it would seem ideal to me
to
place it in a module.
But if I do that then the above declaration fails with can't expose a
friend type.
I have a working solution by getting Bar to bunk down in one of the
calling
classes, but it seems tacky.
regards
Bob

"Bill McCarthy <no spam>" <bill_mcc @ iprimus.com.au> wrote in
message
news:uNBBaCyFEHA.3576 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi Bob,

Do you mean you have :

Class Foo
Public Structure Bar
...
End Structure
End Class

and you want to define an Interface, such as :

Public IFace
Function GetBar() as Foo.Bar
End Interface

If so, Foo must be Public.
Alternatively, don't have Bar nested.



Bill.



"Bob Clegg" <bclegg (AT) clear (DOT) net.nz> wrote in message
news:OoEhpzvFEHA.712 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi,
I have a Data Class that declares a Public struct.
It accepts instances of this struct in some of its function calls.
I now want to put an interface between this class and the calling
classes.

I would like to move the struct out to the module that is housing
the
interface.

But when I do this I get a scoping problem.

The interface declaration of any function that is passing one of
these
structs complains that it can't expose a friend type publicly.

I have tried putting the struct into the interface and I have also
tried
a
public declaration in the module proper and another module.

The only thing that seems to work but doesn't sit comfortably with
me is
to
declare it public in one of the calling classes.
Any thoughts?
thanks
Bob














Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.