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 

How to implement this

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





PostPosted: Fri Jun 09, 2006 9:00 pm    Post subject: How to implement this Reply with quote



Hi,

I have a set of Interfaces, that are implemented by different classes.
Here is an example:


IBSLenexSession = interface
function Course: TBSSwCourse;
function CourseCode: String;
function DisplayText: String;
function LaneCount: Integer;
function LaneMin: Integer;
function LaneMax: Integer;
function Name: String;
function Number: Integer;
function StartDate: TDateTime;
function StartDateTime: TDateTime;
function StartTime: TDateTime;
end; // IBSLenexSession


Now some of the functions only depend on methods available in the
interface. For example:

- CourseCode depends on Course
- LaneCount depends on LaneMin, LaneMax
- DisplayText depends on Name, Number, StartDateTime

I cannot have a common base class because in one case, the
implementation is an XML element class, then another implementation is
based on some other data, coming from a database


My question is, what is an elegant way to implement all the methods,
that depend on methods available in the interface?

Any suggestions?

Thanks

cu Christian
Back to top
SiegfriedN
Guest





PostPosted: Tue Jun 13, 2006 8:53 pm    Post subject: Re: How to implement this Reply with quote



If I underdtand you correctly.. here is my suggestion. (Pseudo like)

ICommonLenexSession = interface
['{B368AF1A-A39A-4157-A4F2-C7CD8398D89B}']
//common routines here..
end;

IXMLLenexSession = interface
['{B368AF1A-A39A-4157-A4F2-C7CD8398D89B}']
//XMLLenexsession routines here..
end;

IDBLenexSession = interface
['{B368AF1A-A39A-4157-A4F2-C7CD8398D89B}']
//DBLenexsession routines here..
end;

TXMLLenexSession = class(TInterfacedObject, IXMLLenexSession,
ICommonLenexSession)
....//routine implementation
end;


TDBLenexSession = class(TInterfacedObject, IDBLenexSession,
ICommonLenexSession)
.... //routine implementation
end;

Then use the QueryIterface method to determine the specific interface
instance type..

Siegs
Back to top
Christian Kaufmann
Guest





PostPosted: Sat Jun 17, 2006 7:26 pm    Post subject: Re: How to implement this Reply with quote



Quote:
If I underdtand you correctly.. here is my suggestion. (Pseudo like)
No, it's not that.


It's more like a partial delegate statement I am looking for.

But I don't want to use delgate, because it is not available in .net /
C# and because I don't want to delegate the whole interface, only some
methods of it.

The only solution I have right now looks like the following code. The
tradeoff is, that I still have to do a lot of typing in each
implementation.

So I'm still looking for a more direct solution.

cu Christian


type
// helper class with the methods, that are based on the core
// methods of my interface
TLenexFormater = class
private
FOwner : Pointer;
public
constructor Create(consts AOwner: IBSLenexSession);
function CourseCode: String;
end;

// one sample of an implementation
TLenexSession = class(TInterfacedObject, IBSLenexSession)
private
FFormater : TLenexFormater;
public
constructor Create;
function Course: TBSSwCourse;
function CourseCode: String;
end;

constructor TLenexFormater.Create(const AOwner: IBSLenexSession)
begin
FOwner := Pointer(AOwner);
end;

function TLenexFormater.CourseCode: String;
begin
Result FormatSomething(IBSLenexSession(FOwner).Course);
end;


constructor TLenexSession.Create;
begin
FFormater := TLenexFormater.Create(Self);
end;

function TLenexSession.CourseCode: String;
begin
Result := FFormater.CourseCode;
end;
Back to top
SiegfriedN
Guest





PostPosted: Tue Jun 20, 2006 4:13 pm    Post subject: Re: How to implement this Reply with quote

Christian Kaufmann wrote:
Quote:
If I underdtand you correctly.. here is my suggestion. (Pseudo like)

No, it's not that.

It's more like a partial delegate statement I am looking for.

But I don't want to use delgate, because it is not available in .net /
C# and because I don't want to delegate the whole interface, only some
methods of it.

The only solution I have right now looks like the following code. The
tradeoff is, that I still have to do a lot of typing in each
implementation.

So I'm still looking for a more direct solution.

cu Christian

Ok, I will give it another go..

IBLenexSession = interface
['{B368AF1A-A39A-4157-A4F2-C7CD8398D89B}']
function GetCourse: TBSSwCourse; stdcall;
procedure SetCourse(Value: TBSSwCourse) stdcall;
function GetLenexFormatter: TLenexFormatter;
..etc..
property Course: TBSSwCourse read GetCourse write SetCource;
property CourseCode: String read GetCourseCode write SetCourseCode;
property Formatter: TLenexFormatter read GetLenexFormatter;
....etc..
end;

now in the implementation classes

TLenexSession1 = class(TInterfacedObject, IBLenexSession)
function GetCourse: TBSSwCourse; stdcall;
procedure SetCourse(Value: TBSSwCourse) stdcall; <- sets coursecode..
function GetLenexFormatter: TLenexFormatter;

//you can repeat the properties from the interface here if needed
property Course: TBSSwCourse read GetCourse write SetCource;
property CourseCode: String read GetCourseCode write SetCourseCode;
property Formatter: TLenexFormatter read GetLenexFormatter;
end;
....

function TLenexSession.GetLenexFormatter: TLenexFormatter;
begin
//Create your specific formatter here..
Result := SpecificLenexFormatter.Create(Self);
end;

Assuming
You want to create specific Formatter classes for each LenexSession class.
You want to extract the CourseCode depending on TBSSwCourse class in
which case the same principle as for the Formatter class applies.

Siegs
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.