Matching design pattern for class wrapping?
- From: "Jason" <stigwood4@xxxxxxxxx>
- Date: 15 Mar 2006 13:27:46 -0800
I am in search of a design pattern which fits my problem. Here's the
situation:
I am writing a socket-server application. This server has multiple
layers: connection, authentication, and interaction. The user
connects, the user authenticates theirself, and the user interacts with
the server.
What I was planning on doing was encapsulating each "state" into a
different object:
Connects - TcpUser
Authenticates - AuthenticationUser (inherits from TcpUser)
Interacts - InteractionUser (inherits from AuthenticationUser)
(ignore the horrible naming - trying to keep it simple ;))
I'm doing this because parent classes needn't know about their
children's functionality (the TcpUser doesn't need to worry about how
it should interact with the server), but children objects can gain
value from their parent's functions. My problem is that the child
classes will be instantiated at later times as the user progresses
through the states of the server; however, they need to refer to
instances of their parent classes created earlier in the program.
Example:
class A {...}
class B implements A {...}
main () {
A classA = new A ();
B classB = classA; //I want to do something like this -
what goes here?
}
If I wrap the parent classes in their children, this would mean I would
have to write wrapper member-functions for every parent function. As
you can imagine, this could quickly get out of control. What I *don't*
want to do:
class A {
string a;
string GetString () { return a;}
}
class B {
A aInstance;
public B (A a) {
aInstance = a;
}
string GetString () { return a.GetString(); }
}
Maybe the solution has nothing to do with patterns and I've just been
thinking about this too long, maybe there's a pattern out there that
fits this problem. Either way, I could use a little friendly advice :)
Jason
.
- Follow-Ups:
- Re: Matching design pattern for class wrapping?
- From: Nick Malik [Microsoft]
- Re: Matching design pattern for class wrapping?
- From: iscy
- Re: Matching design pattern for class wrapping?
- Prev by Date: Re: Implementation of Aggregation
- Next by Date: Pattern Implementation
- Previous by thread: picget, quickly save all images on a web page
- Next by thread: Re: Matching design pattern for class wrapping?
- Index(es):
Relevant Pages
|