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 

Delphi OO design question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Non-Technical
View previous topic :: View next topic  
Author Message
Borland
Guest





PostPosted: Wed Jul 28, 2004 10:30 pm    Post subject: Delphi OO design question Reply with quote



Hi,

For several times I faced the following OO design problem, but never could
find out a solution in Delphi.

I have a class that work as a container for several smaller objets. Each of
the objects should have a reference to the container class.

type
TContainer = class;
TA = class
refCont: TContainer;
end;
TB = class
refCont: TContainer;
end;
TContainer = class
refA: TA;
refB: TB;
end;

As each of the classes has a lot of code, I would like to keep each of them
in separate files.
But I cant imagine how to write it in Delphi as separate files.

Thanks in advance,
Daniel



Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Wed Jul 28, 2004 10:58 pm    Post subject: Re: Delphi OO design question Reply with quote



"Borland" <daniel4321 (AT) terra (DOT) com.br> a écrit dans le message de news:
[email]41082908 (AT) newsgroups (DOT) borland.com[/email]...


Quote:
For several times I faced the following OO design problem, but never could
find out a solution in Delphi.

1. try using abstract classes or interfaces in a common unit to establish
the links and then derive from them into your concrete classes.

2. b.p.d.oodesign is the best group for OO questions.

3. Please change your From name as I doubt you really are Borland.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Phil Shrimpton
Guest





PostPosted: Wed Jul 28, 2004 11:10 pm    Post subject: Re: Delphi OO design question Reply with quote



Borland wrote:

Hi,

Quote:
For several times I faced the following OO design problem, but never
could find out a solution in Delphi.

Change you name from Borland and take your self over to the oodesign
newsgroup, as thats where the people who know hang out.

Phil

Back to top
Daniel Felix
Guest





PostPosted: Thu Jul 29, 2004 1:51 am    Post subject: Re: Delphi OO design question Reply with quote

First, I would like to apologize for the wrong 'from name'. I didn't notice
(and understand why) that the newsgroup software assumed the server name as
my own name...

And thanks for the advice about the interfaces. It seems it will create an
overhead of new declarations, but I think it will surely be better than a
bunch of 15K lines in a sigle file as the program was written before.


Back to top
Daniel Becroft
Guest





PostPosted: Thu Jul 29, 2004 2:08 am    Post subject: Re: Delphi OO design question Reply with quote

Borland wrote:

Quote:
Hi,

For several times I faced the following OO design problem, but never could
find out a solution in Delphi.

I have a class that work as a container for several smaller objets. Each of
the objects should have a reference to the container class.

type
TContainer = class;
TA = class
refCont: TContainer;
end;
TB = class
refCont: TContainer;
end;
TContainer = class
refA: TA;
refB: TB;
end;

As each of the classes has a lot of code, I would like to keep each of them
in separate files.
But I cant imagine how to write it in Delphi as separate files.

Just create a separate unit for each of the classes (A.pas, B.pas, Container.pas), and add a
reference in the uses clause of each unit to the other.

For example,

unit Container;

interface

uses A, B;

and

unit A;

interface

uses Container;

Hope that helps,

--
Daniel Becroft
; =================================
"Real computer scientists don't comment their code. The identifiers are so long they can't afford
the disk space."

"Blue sparks and white smoke, the two most expensive components of any electrical system, and once
used up will cost a fortune to replace."

Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Thu Jul 29, 2004 6:51 am    Post subject: Re: Delphi OO design question Reply with quote

"Daniel Becroft" <djcbecroft (AT) hotmail (DOT) com> a écrit dans le message de news:
[email]xn0dlc9v83rx3h000 (AT) newsgroups (DOT) borland.com[/email]...

Quote:
Just create a separate unit for each of the classes (A.pas, B.pas,
Container.pas), and add a
reference in the uses clause of each unit to the other.

Have you even tried your solution before posting? This will cause a circular
reference which cannot be compiled in Delphi.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Daniel Becroft
Guest





PostPosted: Thu Jul 29, 2004 6:59 am    Post subject: Re: Delphi OO design question Reply with quote

Joanna Carter (TeamB) wrote:

Quote:
"Daniel Becroft" <djcbecroft (AT) hotmail (DOT) com> a icrit dans le message de news:
[email]xn0dlc9v83rx3h000 (AT) newsgroups (DOT) borland.com[/email]...

Just create a separate unit for each of the classes (A.pas, B.pas,
Container.pas), and add a
reference in the uses clause of each unit to the other.

Have you even tried your solution before posting? This will cause a circular
reference which cannot be compiled in Delphi.

Hmm, I have a similar solution in code that I use, and it compiles fine with D6 Personal.

Go figure ...

--
Daniel Becroft
; =================================
"Real computer scientists don't comment their code. The identifiers are so long they can't afford
the disk space."

"Blue sparks and white smoke, the two most expensive components of any electrical system, and once
used up will cost a fortune to replace."

Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Thu Jul 29, 2004 7:06 am    Post subject: Re: Delphi OO design question Reply with quote

"Daniel Becroft" <djcbecroft (AT) hotmail (DOT) com> a écrit dans le message de news:
[email]xn0dlcmz6lgep8000 (AT) newsgroups (DOT) borland.com[/email]...

Quote:
Hmm, I have a similar solution in code that I use, and it compiles fine
with D6 Personal.


Then I suggest you set up a new project in D6, ensure that the mutual
references in the uses clauses are in the interface sections of each unit,
as in your post, and try compiling it.

Please post the result of your test.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Jim Cooper
Guest





PostPosted: Thu Jul 29, 2004 8:56 am    Post subject: Re: Delphi OO design question Reply with quote


Quote:
Hmm, I have a similar solution in code that I use, and it compiles fine with D6 Personal.

In that case, one of your uses clauses is in the implementation section,
not the interface section

Cheers,
Jim Cooper

_______________________________________________

Jim Cooper [email]jim (AT) falafelsoft (DOT) com[/email]
Falafel Software http://www.falafelsoft.co.uk
_______________________________________________

Back to top
Kirk Halgren
Guest





PostPosted: Thu Jul 29, 2004 10:59 am    Post subject: Re: Delphi OO design question Reply with quote

"Daniel Becroft" <djcbecroft (AT) hotmail (DOT) com> wrote

<snip>

Quote:
"Blue sparks and white smoke, the two most expensive components of any
electrical system, and once
used up will cost a fortune to replace."

Once you open the case and let out the smoke, they stop working. ;-)

Kirk Halgren

"I find television very educating. Every time somebody turns on the
set, I go into the other room and read a book."
-- Groucho Marx, 1890-1977



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Non-Technical 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.