Can I write as follow?

  • Thread starter Thread starter ABC
  • Start date Start date
A

ABC

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

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

void SaveSession() { ............. };
void LoadSession() { ............. };
}
 
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.
 
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.
 
ABC said:
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.
 
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.
 
ABC said:
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.
 
Back
Top