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 

singleton references

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





PostPosted: Wed Oct 29, 2003 9:34 pm    Post subject: singleton references Reply with quote



It's getting so that I have a small number of
singletons running around that handle support
roles.

In some projects, I've had sort of a master
controller that held references to these.

I'm not thrilled with this because you quickly
run afoul of the Law of Demeter, e.g. the more
dots, the more coupled your objects.

OTOH, I am not completely comfortable with
lots of these global references running around either.

Your preference?
Other ideas?

--
Thanks,
Brad White


Back to top
Joanna Carter
Guest





PostPosted: Wed Oct 29, 2003 9:43 pm    Post subject: Re: singleton references Reply with quote



Brad White wrote:

Quote:
Your preference?
Other ideas?

Use a class of class methods. Any instance data can be held in
implementation section variables.

Joanna

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



Back to top
Lawrence Thurman
Guest





PostPosted: Thu Oct 30, 2003 5:00 pm    Post subject: Re: singleton references Reply with quote



If the singleton is written to the true form o a singleton pattern then
you should not have to have Global variables


I override the NewInstance method from TObject
to control whether or no the Class instantiates or just updates the refcount

all of this is encapsualted with a class;

however you can not inherit from this class
why?
think about it - you would have to override everything that is
controlling the singleton
otherwise there qould be one class - the child XOR the parent

hope this helps

"Brad White" <bwhite at inebraska.com> wrote

Quote:
It's getting so that I have a small number of
singletons running around that handle support
roles.

In some projects, I've had sort of a master
controller that held references to these.

I'm not thrilled with this because you quickly
run afoul of the Law of Demeter, e.g. the more
dots, the more coupled your objects.

OTOH, I am not completely comfortable with
lots of these global references running around either.

Your preference?
Other ideas?

--
Thanks,
Brad White





Back to top
Danny Heijl
Guest





PostPosted: Thu Oct 30, 2003 7:57 pm    Post subject: Re: singleton references Reply with quote

Quote:
however you can not inherit from this class


You can inherit from this singleton class by Lucian Radulescu :

http://www.ez-delphi.com/sources/usingle.htm


Danny
---



Back to top
Brad White
Guest





PostPosted: Thu Oct 30, 2003 8:26 pm    Post subject: Re: singleton references Reply with quote

"Lawrence Thurman" <lawrence (AT) powerofzen (DOT) com> wrote

Quote:
however you can not inherit from this class
why?
think about it - you would have to override everything that is
controlling the singleton
otherwise there qould be one class - the child XOR the parent


John,

Do you want to answer this or should I?

--
Thanks,
Brad White



Back to top
Lawrence Thurman
Guest





PostPosted: Mon Nov 03, 2003 5:42 pm    Post subject: Re: singleton references Reply with quote

But if you inherit from TAClass with TChild1 and TChild2 and polymorph
each of the children I believe that
you can only construct one of the other, but trying to construct both will
not happen due to the refcount being incremented.

"Danny Heijl" <danny.heijl_ (AT) _pandora (DOT) be> wrote

Quote:
however you can not inherit from this class


You can inherit from this singleton class by Lucian Radulescu :

http://www.ez-delphi.com/sources/usingle.htm


Danny
---





Back to top
John Elrick
Guest





PostPosted: Mon Nov 03, 2003 11:06 pm    Post subject: Re: singleton references Reply with quote


"Brad White" <bwhite at inebraska.com> wrote

Quote:
"Lawrence Thurman" <lawrence (AT) powerofzen (DOT) com> wrote in message
news:3fa1438a (AT) newsgroups (DOT) borland.com...
however you can not inherit from this class
why?
think about it - you would have to override everything that is
controlling the singleton
otherwise there qould be one class - the child XOR the parent


John,

Do you want to answer this or should I?

Well...it's true, using that pattern. It's one of the reasons I adopted the
IFooFactory approach instead.



John



Back to top
John Elrick
Guest





PostPosted: Mon Nov 03, 2003 11:52 pm    Post subject: Re: singleton references Reply with quote

"Brad White" <bwhite at inebraska.com> wrote

Quote:
It's getting so that I have a small number of
singletons running around that handle support
roles.

In some projects, I've had sort of a master
controller that held references to these.

I'm not thrilled with this because you quickly
run afoul of the Law of Demeter, e.g. the more
dots, the more coupled your objects.

Very true.

Quote:

OTOH, I am not completely comfortable with
lots of these global references running around either.

Your preference?
Other ideas?

I wouldn't worry too much until there is a real issue to address. If you
have 100 valid Singletons, then you have 100 valid Singletons.

OTOH, if you do notice the bad smells of large uses clauses, difficulty in
locating the "correct" Singleton, or "if only this Singleton did _this_",
then I would say it is time to refactor the code.

The design will speak to you.


John



Back to top
Brad White
Guest





PostPosted: Thu Nov 06, 2003 8:04 pm    Post subject: Re: singleton references Reply with quote

"John Elrick" <jelrick (AT) adelphia (DOT) net> wrote

Quote:
I wouldn't worry too much until there is a real issue to address. If you
have 100 valid Singletons, then you have 100 valid Singletons.

OTOH, if you do notice the bad smells of large uses clauses, difficulty in
locating the "correct" Singleton, or "if only this Singleton did _this_",
then I would say it is time to refactor the code.

The design will speak to you.



Trust the source...
--
Thanks,
Brad White



Back to top
John Elrick
Guest





PostPosted: Fri Nov 07, 2003 2:48 pm    Post subject: Re: singleton references Reply with quote


"Brad White" <bwhite at inebraska.com> wrote

Quote:
"John Elrick" <jelrick (AT) adelphia (DOT) net> wrote in message
news:3fa6ea28$2 (AT) newsgroups (DOT) borland.com...
I wouldn't worry too much until there is a real issue to address. If
you
have 100 valid Singletons, then you have 100 valid Singletons.

OTOH, if you do notice the bad smells of large uses clauses, difficulty
in
locating the "correct" Singleton, or "if only this Singleton did
_this_",
then I would say it is time to refactor the code.

The design will speak to you.



Trust the source...

And your gut<g>


John



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.