471,310 Members | 1,057 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Can I write as follow?

ABC
interface IWebPage
{
class SessionStructure {};
void SaveSession();
void LoadSession();
}

public class BasePage : IWebPage
{
class SessionStructure
{
int a;
int b;
}

void SaveSession() { ............. };
void LoadSession() { ............. };
}
Jan 12 '06 #1
8 1001
Well, there are a few problems here.

The first is that you should make the Save and LoadSession methods on
the BasePage class virtual, so that they can be overridden by derived
classes.

However, you can not extend the SessionStructure class like that. You
would have to create a new type.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ABC" <ab*@abc.com> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
interface IWebPage
{
class SessionStructure {};
void SaveSession();
void LoadSession();
}

public class BasePage : IWebPage
{
class SessionStructure
{
int a;
int b;
}

void SaveSession() { ............. };
void LoadSession() { ............. };
}

Jan 12 '06 #2
KJ
No. As the compiler will tell you, interfaces cannot declare types.
Perhaps you might share why you want to do this, so alternatives may be
offered.

Jan 12 '06 #3
ABC
What alternatives can do similar case?
"KJ" <n_**********@mail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
No. As the compiler will tell you, interfaces cannot declare types.
Perhaps you might share why you want to do this, so alternatives may be
offered.

Jan 12 '06 #4
ABC <ab*@abc.com> wrote:
What alternatives can do similar case?


We need to know what you're actually trying to do before we can answer
that. It's not at all obvious how you expected to be able to use that
interface.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 12 '06 #5
"ABC" <ab*@abc.com> wrote in message
news:Ob*************@TK2MSFTNGP11.phx.gbl...
What alternatives can do similar case?


What are you actually trying to do...?
Jan 12 '06 #6
ABC
as each webpage has difference session structure to hold data, but each
webpage have similar behaviors to load and save session data to sessions
pool. I want to standardize the programmers coding, so the interface should
have a base session class and programmers should do some codes to add
properties to session structures, all programmers must use same session
structure name. I don't like they have own programming styles.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ABC <ab*@abc.com> wrote:
What alternatives can do similar case?


We need to know what you're actually trying to do before we can answer
that. It's not at all obvious how you expected to be able to use that
interface.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 12 '06 #7
ABC <ab*@abc.com> wrote:
as each webpage has difference session structure to hold data, but each
webpage have similar behaviors to load and save session data to sessions
pool. I want to standardize the programmers coding, so the interface should
have a base session class and programmers should do some codes to add
properties to session structures, all programmers must use same session
structure name. I don't like they have own programming styles.


No, you can't enforce naming like this. (Nor would the interface be
expressing anything you could actually *use* given only a reference to
an instance of the interface.) I can't see how it's agood idea though
anyway - it would make things very awkward if you had two web pages
which actually needed the same session structure. They'd have to
declare the same thing twice, which is bad practice.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 12 '06 #8
KJ
Have you considered using inheritance, or a combination of inheritance
and delegation?

Jan 12 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

33 posts views Thread by Xah Lee | last post: by
1 post views Thread by Vincy | last post: by
13 posts views Thread by Stumped and Confused | last post: by
reply views Thread by Ravikanth[MVP] | last post: by
1 post views Thread by leopl | last post: by
reply views Thread by Med | last post: by
reply views Thread by rosydwin | last post: by

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.