Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Obvious to You


Obvious to you

Ms Stob, whose application to the Gang of Three Hundred and Seven is being processed, wished to present her latest design pattern — a brilliant codification of established standard practice — for your consideration. But she seems to have had difficulty concentrating on the task in hand.

Beep

Intent

Attract operator's or user's attention to the machine by making some sort of noise.

(Some sort of noise. What might be appropriate here I wonder? Oh yes. I remember. Arrrrrrrrrrrgh!)

 

Also known as

Ping, Bell

(Doh!)

 

Motivation

Sometimes it is necessary to alert the user to a program's current state, because for example it has completed a task or encountered an error. A convenient way to accomplish this is with a brief audio tone, of fixed or varying pitch, played through the computer's speaker, or some other sound-making device attached to the machine and controllable through software.

(Motivation: temporary insanity. What? Who says that's not a motivation? All right then, greed. Are you happy now? Does that make you feel superior?

What happened was this. I went out for a drink with Simon, you know Simon who always asks how much you are earning? and how come the other people who were in our year are rich and we are not? And we had an evening of escalating self-pity, as one sometimes does, and about at the third glass of red wine he said: have you seen that woman Maria Self-Promotion on the news? Now there's a person who is going somewhere. I bet she doesn't drive a second hand Ford bloody Mondeo.)

 

Applicability

Use Beep

  • when timely intervention by the operator is imperative
  • if the machine does not have a display device, or the display device may be obscured or switched off
  • if the task may be running in background, or its GUI window obscured
  • if the nature of the application makes it especially likely that the operator may be blind or visually handicapped (although of course it is always good practice to consider such users).

(So he said, I bet you wouldn't mind a few quid than Verity, it's not as though you are oozing with it. Let me freshen that glass up for you, because I have an idea.)

Collaborations

A Beeper object is often implemented as a Singleton.

(Safe? he said in disbelief. Safe? It's as safe as a bet against the South African cricket team. Now if you can spring your nest egg from the frigid clutches of the Salisbury and Cowpat Former Building Society tomorrow, meet me here and I'll introduce you to my online broker.)

 

Consequences

A program that uses the Beep pattern may be able work on a machine where the video display is disabled. An obvious example of this is the pattern of beeps used by the Power On Self-Test (POST) program used by PC BIOSes. It is possible to diagnose hardware faults, to some extent, if the video card has failed or if none is plugged in.

(Well, we can forget the US holiday, obviously, it's a week with Mum in Bournemouth for me.

It's turned me into a kind of Robocop, that bizarre 22nd Century cyborg that ran an adapted version of MS-DOS. Except that Murphy, as I recall the eponymous semi-metallic bobby was called, used to wake up with the words COMMAND.COM dancing before his eyes, whereas the phrase that rolls up on my mental teleprompter at boot up is just.too.late.com.)

 

Implementation

A nave C++ implementation of Beep might look something like this:

cout << '\a';

In practice it is often desirable to allow the user to control whether or not the application makes a noise. For example, the user of a radio pager might wish to turn it off while attending a meeting or classical music concert. In this case, it would make sense to write code like this

if (enabled) cout << '\a';

where enabled is a boolean state variable of a Beeper class for which suitable accessor methods have been provided.

(Mum says Wouldn't it be better to save some of your money, dear? And I say up to a point Mum. But Simon says Click here! And Verity clicks there. Simon says Spend! And Verity spends. Simon says, Simon says. Where were you, oh generally unreliable ISP with permanently engaged lines and internal routing problems, the night that I needed you? You were fully operational, you traitor!)

 

Known Uses

The Beep pattern is widely used in operating systems. Microsoft Windows, for example, can be configured so that when the Caps Lock key is pressed, a brief tone is heard — alerting the user who thinks he hit the Tab key THAT HE IS NOW

SHOUTING.

(None at all. As I understand it, my just.too.late.com holding is now worth less than the paper that it isn't printed on. My only option is to wait until the day that their website's business takes off. What? Oh they sell kits that let you make homegrown genetically modified ostrich meat. Apparently they are having teething problems in that the eggs tend to get broken in the post.)

 

Related Patterns

Click, Warble, Booster, Singleton (inevitably), Messagebox

(Motless Fool, Sucker, e.e. jit. Halfwit, Nasdaquette.)

 

Comment

This pattern may seem obvious to you. But common experiences are often worth documenting, as that way you may be able to spare others the pain of learning the lesson.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.