BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strategy and command(long)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Andrea Raimondi
Guest





PostPosted: Sat May 21, 2005 2:19 pm    Post subject: Strategy and command(long) Reply with quote



Hello.

Building an IRC client, I find myself needing a way to transform Delphi
code to IRC protocol, so I'm creating a series of classes that look like
this:

Type
TIRCCommand = ( ic_Nick, ic_Message,ic_Password );

TCommand = class
private
FRecipient: String;
FSender: String;
public
constructor Create(ASender : String;ARecipient : String);
function AsRawCommand : String;virtual;abstract;
property Sender : String read FSender;
property Recipient : String read FRecipient;
end;

TCommandClass = class of TCommand;

TCommandItem = class
private
FCmdClass: TCommandClass;
FCmd: TIRCCommand;
procedure SetCmdClass(const Value: TCommandClass);
public
constructor Create(ACmd : TIRCCommand);
property Cmd : TIRCCommand read FCmd;
property CmdClass : TCommandClass read FCmdClass write SetCmdClass;
end;

TCommandIdItem = class
public
property CmdId : Integer;
property CmdIdRef : TCommandItem;
end;

TCommandStrategy = class
private
function GetCommandRef(Index: TIRCCommand): TCommandClass;
function GetCommandStr(Index: String): TCommandClass;
private
FCmdList : TObjectList;
FCmdIdList : TObjectList;
protected
function InternalTranslate(Str : String) : TIRCCommand;
function FindCommandClass(ACmd : TIRCCommand) : TCommandClass;
function StrHash(Str : String) : Integer;
procedure RegisterCommandId(Str : String;ACmd : TIRCCommand);
procedure RegisterCommandRef(ACmd : TIRCCommand;
CmdClass : TCommandClass);
public
procedure AfterConstruction;override;
destructor Destroy;override;
property CommandRef[ Index : TIRCCommand ] : TCommandClass
read GetCommandRef;
property CommandStr[ Index : String ] : TCommandClass
read GetCommandStr;
end;

As you can see the idea is fairly simple: when I send a string
command, I obtain the correct command class to be istantiated so that I
just need to call a "write" using Command.AsRawCommand .

That is all good, but I'd like to also be able to use all this when I
receive a command, I should probably make the IRCCommand part public,
thus enabling to only search and translate, but then?

I was thinking to modify it this way:

Type

TIRCCommandBase = class
private
FRecipient: String;
FSender: String;
public
constructor Create(ASender : String;ARecipient : String);
property Sender : String read FSender;
property Recipient : String read FRecipient;
end;

TSentCommand = class(TIRCCommandBase)
private
FRecipient: String;
FSender: String;
public
function AsRawCommand : String;virtual;abstract;
end;

TReceivedCommand = class(TIRCCommandBase)
public
procedure Update;virtual;abstract;
end;

Yes, I'd do a split and use TReceivedCommand as subject for observers.
What would those need to look like to make the class well designed?

Any comment on the code(this later one or the previous) is welcome, as
long as suggestions/critics are substantiated(99% of times this is
indeed the case here).

TIA,

Andrew
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.