 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Christian Kaufmann Guest
|
Posted: Fri Jun 09, 2006 9:00 pm Post subject: How to implement this |
|
|
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
|
Posted: Tue Jun 13, 2006 8:53 pm Post subject: Re: How to implement this |
|
|
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
|
Posted: Sat Jun 17, 2006 7:26 pm Post subject: Re: How to implement this |
|
|
| 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
|
Posted: Tue Jun 20, 2006 4:13 pm Post subject: Re: How to implement this |
|
|
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 |
|
 |
|
|
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
|
|