473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

C++ "packages"?

Hi I've recently designed and implemented a menu system.

Basically I have several classes:

Menu - this contains MenuItems

MenuItems(base class) - can be either a SubMenu or a Switch (Sub menus
display a new menu, switches allow the user - by pressing the space bar
say - to toggle between the switches "options")

Now, Menus are basically a collection of MenuItems. Ones creates MenuItems
(either Submenus or Switches or some future types) and the does a
Menu.AddItem ( new switch());

Problem: when I came to creating a Menu in my code, I realised I had to not
only include Menu.h, but also submenu.h and switch.h.

Also I have to specifically create Switch/Submenu objects then add them to
the menu (menu.additem).

Now all this is fine, but what i was really going for was a more
"encapsulated" type solution.

Really I want to just include one header "menu.h" and also not have to
create separate objects whose only purpose is to be added to the menu
object.

My main reason to think I have made a design "gaff" is that MenuItems have
no meaning on their own! The only point of their existence is as a part of a
Menu object

Any thoughts on this?

Dean

P.S. thanks for all the response to my previous post(s) about the tightly
coupled graphics objects. I'm realising that 1) i still have a LOT to learn.
2) This is a great place to do it! :-)
Feb 1 '06 #1
4 1636
Jim Langston wrote:
Well, this is your interface showing. One way to do it, and not one I'm
suggesting, but one way would be to have your Menu class create the
subclasses itself and add them. I probably wouldn't go this way though.
Agreed.
The only real suggestion I would have would be in have your menu.h include
the submenu.h and switch.h itself. All with include guards of course.


I don't think this is a good idea. As a rule, one should only #include
what one explicitly needs. Excess #includes, especially in headers,
are the source of major build slowdowns far too often. Builds take
longer and happen more often due to tightly interwoven dependencies.
It violates the principle of "you don't pay for what you don't use"
which is core to the language.

Luke

Feb 1 '06 #2
Ed

Chocawok skrev:
Hi I've recently designed and implemented a menu system.
Snwip. Now all this is fine, but what i was really going for was a more
"encapsulated" type solution.


I'm a C++ virgin, but I thought C++ had namespaces now with the STL?

I'm sure I've missed the point (like most virgins), but I'm surprised
that these aren't precisely the, "Packages," you were looking for.

..ed

--
www.EdmundKirwan.com - Home of The Fractal Class Composition.

Feb 1 '06 #3
In article <HP*********************@fe2.news.blueyonder.co.uk >,
"Chocawok" <no****@nospam.com> wrote:
Hi I've recently designed and implemented a menu system.

Basically I have several classes:

Menu - this contains MenuItems

MenuItems(base class) - can be either a SubMenu or a Switch (Sub menus
display a new menu, switches allow the user - by pressing the space bar
say - to toggle between the switches "options")

Now, Menus are basically a collection of MenuItems. Ones creates MenuItems
(either Submenus or Switches or some future types) and the does a
Menu.AddItem ( new switch());

Problem: when I came to creating a Menu in my code, I realised I had to not
only include Menu.h, but also submenu.h and switch.h.
You only have to include submenu.h and switch.h if you are actually
making new submenus or switches. This is to be expected and there is
nothing wrong with it.
Also I have to specifically create Switch/Submenu objects then add them to
the menu (menu.additem).
Of course, the Menu itself doesn't know what kind of MenuItems you are
going to need, so you have to make them.
Now all this is fine, but what i was really going for was a more
"encapsulated" type solution.

Really I want to just include one header "menu.h" and also not have to
create separate objects whose only purpose is to be added to the menu
object.

My main reason to think I have made a design "gaff" is that MenuItems have
no meaning on their own! The only point of their existence is as a part of a
Menu object


Give MenuItem objects more purpose. It is common in Menu sub-systems
such as yours for the MenuItem to be able to call some method when
"selected". Obviously, you are going to have to create the MenuItems in
your program in order to make sure they call the right code when
selected.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 2 '06 #4

"Luke Meyers" <n.***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...

I don't think this is a good idea. As a rule, one should only #include
what one explicitly needs. Excess #includes, especially in headers,
are the source of major build slowdowns far too often. Builds take
longer and happen more often due to tightly interwoven dependencies.
It violates the principle of "you don't pay for what you don't use"
which is core to the language.

Thanks. You have just identified yet another reason to
prefer Ada over C++.

Richard Riehle
Feb 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hal Vaughan | last post by:
I'm using JDK 1.4.1 for Java 2. According to the API docs, I can use javax packages, but when I add: import javax.crypto; I get an error that it can't find the package. Is there some special...
2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
6
by: Luc Saffre | last post by:
Hello, I had a strange problem when freezing (using either py2exe or McMillan installer) a script that imports reportlab (which imports PIL (which imports FixTk))). - Python 2.3.3c (also with...
2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
4
by: Jochen Demuth | last post by:
Hi, I am trying to install ZWiki on Zope 2.5.1 / Debian 2.4.20-bf2.4-xfs. First I copied the contents of the ZWiki-0.32.0.tgz to the Products-directory under SOFTWARE_HOME: This is what it...
0
by: Humpdydum | last post by:
When I run python setup.py bdist --format=zip on Windows 2000, with this setup.py: from distutils.core import setup setup(name="test", version="1.0", description="blabla",
0
by: David T | last post by:
Has anyone run across this error? When calling any of several visualization routines from FiPy, Python quits with a Bus Error I'm using MacOS X Tiger 10.4.3, and I've tried several builds...
0
by: Michael Bruzdzinski | last post by:
I am hoping that some one in the DB2 community is a 'pack rat' and has a copy of the article "The ABCs of Plans and Packages" by Nicola Nur, which was written in 1994. It appeared in the Database...
14
by: Nader Emami | last post by:
I have installed "TurboGears" and I would install 'pysqlite' also. I am a user on a Linux machine. If I try to install the 'pysqlite' with 'easy_install' tool I get the next error message. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.