Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Can I avoid using a global?!

Reply
Thread Tools

Can I avoid using a global?!

 
 
mike3
Guest
Posts: n/a
 
      11-25-2011
On Nov 24, 6:45*am, Goran <goran.pu...@gmail.com> wrote:
> On Nov 23, 10:25*pm, mike3 <mike4...@yahoo.com> wrote:
>
>
>
> > On Nov 23, 1:02*am, Goran <goran.pu...@gmail.com> wrote:

>
> > > On Nov 22, 9:46*pm, mike3 <mike4...@yahoo.com> wrote:

>
> > > > On Nov 22, 7:08*am, Goran <goran.pu...@gmail.com> wrote:

>
> > > > > On Nov 22, 11:02*am, mike3 <mike4...@yahoo.com> wrote:
> > > > <snip>
> > > > > What I am talking about here is also known as "interface segregation
> > > > > principle": for a given part of your code, you want to pass in things
> > > > > it needs to do the work. To do that in a clean way, a good way isto
> > > > > create the interface (from the rest of your code) to another part, and
> > > > > pass that interface in. You don't want one big great massive thing
> > > > > that can do everything, and then cherry-pick what you need from that
> > > > > great big thing. That's akin to a global variable, except that you
> > > > > avoided having it as one, by passing it -everywhere- through a
> > > > > parameter.

>
> > > > However, the display isn't a "great big thing that does everything",
> > > > is
> > > > it? Aren't you talking about this?:

>
> > > >http://en.wikipedia.org/wiki/God_object

>
> > > Yes.

>
> > > > But I fail to see how the display ends up being one of those. It's
> > > > just
> > > > a display.

>
> > > It's a display who, I presume displays all sorts of stuff (text,
> > > graphics, possibly interacts with the user). But your concern is to
> > > emit messages. If so, your "clients" of the display see one great big
> > > thing that does text/graphics/interaction, and yet, they merely want
> > > to emit messages. So in that sense, it is a God object.

>
> > > BTW:http://en.wikipedia.org/wiki/Solid_%...nted_design%29

>
> > > Goran.

>
> > So then should the "display" object be partitioned up into a few more,
> > like one to do messages, one to do graphics, one to handle input?

>
> I was merely commenting on "various places" who want to "display
> messages". In general, even without knowing a lot about the rest of
> the code, I felt it's safe to say that it's a bad idea to give them a
> display object, even if it's a display that displays messages. Hence I
> reacted: passing a mere "MessageReceiver" --interface-- is better.
>
> Now, whether MessageReceiver interface will be implemented by
> DisplayWindow, or whether it will be a separate object that references
> DisplayWindow, I don't know. I would venture that a separate object is
> better because... What if you're not showing DisplayWindow object for
> message? I'd personally destroy the object: not on screen, not in
> "code". If so, you --need-- a separate object to receive messages. If,
> however, you elect to have DisplayWindow object always there, then he
> itself can be your MessageReceiver. But dig this: either way you
> decide, parts of your program that depend on services of a
> MessageReceiver --do not care-- about any of that. As long as you can
> pass them a MessageReceiver, you can do what you want "behind" it. In
> other words, you just gained a thing caller looser coupling, and that,
> in programming, means freedom .
>
> Goran.


So this would allow one to not only display messages, but also, e.g.
suppress
output by passing in a "null" (an object with "MessageReceiver"
interface
that just does nothing), or direct output to a file, or another
display, etc.
Lots of possibilities.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using enums to avoid using switch/if aks_java Java 30 03-25-2010 11:48 AM
Can't avoid "References to generic type List<E> should beparameterized" warning here can I ? Sébastien de Mapias Java 7 05-29-2008 06:52 PM
Avoid having a SQL express for web parts and avoid personalization Roger23 ASP .Net 2 10-12-2006 10:54 PM
using TagPrefix to avoid having @ Register directives on pages using custom controls Shan McArthur ASP .Net Building Controls 2 06-30-2005 02:37 PM
Avoid wasting time or how to avoid initialization Alexander Malkis C++ 8 04-13-2004 11:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57