473,406 Members | 2,710 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,406 software developers and data experts.

Best practices for grouping namespaces, classes, etc

_DD
I believe Balena's Best Practices book suggests grouping quite a few
classes into each namespace. I don't remember a number, but this has
me curious about how other programmers handle this.

If classes are obviously related, then I use the same namespace.
Problem is that this doesn't seem to happen often. I could understand
Balena's numbers in the context of a specific library, but in the
scope of a large program, many corners are covered. I often end up
with a single namespace per project.

I also often end up with only a couple classes per project. This
happens for a different reason: I often run into occasions where
projects end up cross-dependent, so they need to be split up. Of
course that forces the size of each project to be smaller.

Comments? How many classes do you end up with per project?
How many classes or projects per namespace?

May 16 '06 #1
3 3985
Not the number of classes, but their context and logic are major factors for
decoupling classes into different namespaces.
Even if you have 5-7 classes in single app you divide them by context. For
example. classes that are responsible for UI should be detached from those
that are responsible for you logic, and these ones in its turn detached for
Input/Output (data logic) classes
I believe Balena's Best Practices book suggests grouping quite a few
classes into each namespace. I don't remember a number, but this has
me curious about how other programmers handle this.

If classes are obviously related, then I use the same namespace.
Problem is that this doesn't seem to happen often. I could understand
Balena's numbers in the context of a specific library, but in the
scope of a large program, many corners are covered. I often end up
with a single namespace per project.

I also often end up with only a couple classes per project. This
happens for a different reason: I often run into occasions where
projects end up cross-dependent, so they need to be split up. Of
course that forces the size of each project to be smaller.

Comments? How many classes do you end up with per project?
How many classes or projects per namespace?


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

May 16 '06 #2
_DD
On Mon, 15 May 2006 23:39:01 -0700, Michael Nemtsev
<Mi************@discussions.microsoft.com> wrote:
Not the number of classes, but their context and logic are major factors for
decoupling classes into different namespaces.
Even if you have 5-7 classes in single app you divide them by context. For
example. classes that are responsible for UI should be detached from those
that are responsible for you logic, and these ones in its turn detached for
Input/Output (data logic) classes


Thanks for your reply, Michael. Yeah, I was curious about how others'
projects end up as far as namespace density. I often end up with one
file per namespace, as you'd expect in some cases, but the only 'Best
Practices' info that I've seen that addresses this (Balena's book)
seems to imply that the average 'solution' will have many more than
I've ended up with. I also expect that to vary by type and diversity
of project

Sometimes I may take the 'context' categorization to too fine a level.
Just wondering about others' thoughts on organizing..
I also often end up with only a couple classes per project. This
happens for a different reason: I often run into occasions where
projects end up cross-dependent, so they need to be split up. Of
course that forces the size of each project to be smaller.


And this gets awkward. The usual thing that I've run into is...
Classes need interfaces as a low-level construct. Then the working
classes are built according to that. Then a top-level class (factory,
whatever) makes use of the working classes, referring to them by
interface.

Basically that results in the lowest and highest strata being built to
an abstraction (Interfaces), with the practical 'worker'
implementation classes in the middle. Fine, except that I'd love to
group the interfaces and factories together into one project--they do
belong together. But alas... circular dependency. This seems like it
would happen a lot.
May 17 '06 #3


_DD wrote:
On Mon, 15 May 2006 23:39:01 -0700, Michael Nemtsev
<Mi************@discussions.microsoft.com> wrote: Thanks for your reply, Michael. Yeah, I was curious about how others'
projects end up as far as namespace density. I often end up with one
file per namespace, as you'd expect in some cases, but the only 'Best
Practices' info that I've seen that addresses this (Balena's book)
seems to imply that the average 'solution' will have many more than
I've ended up with. I also expect that to vary by type and diversity
of project
I would say that "best-practice" depends very little on the number of
elements in the namespace, but on whether grouping or isolating on the
namespace level makes it easier to read. If there are many members in
the namespace you can go looking for groups, but don't look harder than
nessesary :)

Don't introduce namespaces to reduce the number of elements, apply
namespaces where grouping is natural.

One example of the "5-7 elements in a group" rule being applied
completely out of scope is the WinXP default ControlPanel, where more or
less random groupings have been done to lower the amount of elements in
the control-panel. That does *not* make it easier to find an element, it
makes it *harder*.

Basically that results in the lowest and highest strata being built to
an abstraction (Interfaces), with the practical 'worker'
implementation classes in the middle. Fine, except that I'd love to
group the interfaces and factories together into one project--they do
belong together. But alas... circular dependency. This seems like it
would happen a lot.


That circular dependency is created by your design. You are depending on
a 1:1 correspondence betweeen interface and implementation, right?
Your factories are bound to a specific implementation of the interface,
and thus reference that implementation.

Should you wish for more decoupling, declare interfaces for the
factories and use registration for them:

=== interface assembly ===
interface ITFactory {
T produceT(...);
}
public class TFactory {
public static Instance;
}

=== implementation assembly ===
public MyTFactory: ITFactory {
T produceT(...) { ... };
}

=== usage ===
ITFactory tproducer = TFactory.Instance;
// this code has *no* idea about how ITFactory is implemented
// and can be in any assembly.
// Works if *anyone* have set TFactory.Instance
tproducer.produceT(...);

=== anywhere, before usage ===
if ( InOneMind )
TFactory.Instance = new MyTFactory();
else
TFactory.Instance = new SomeOtherTFactory();


--
Helge
May 17 '06 #4

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

Similar topics

1
by: Miranda Evans | last post by:
Seeking reference material (a url, a book, an article) that offers advice and guidelines for organizing classes within files. For example, assume two classes: 1) SuperABC - a superclass 2)...
1
by: William Sullivan | last post by:
I've been trying to research my question, but I haven't found a difinitive guide yet. My company is starting to build projects using dotnet. There isn't much coordination in namespaces, so I am...
217
by: gyromagnetic | last post by:
The following url points to an article written by Damian Conway entitled "Ten Essential Development Practices": http://www.perl.com/pub/a/2005/07/14/bestpractices.html Althought the article has...
3
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use...
1
by: Vincent V | last post by:
Hey i am just starting a new project and from the start i want to make sure my app is as Object Orientated as possible I have a couple of questions in relation to this Question 1: Should i...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
14
by: Bert Vandenberghe | last post by:
Hi, I was wondering if there are any best practices on the creation of webmethods? I'll try to explain this a little more: My problem is that we are changing an existing (large) DCOM application...
2
by: steve | last post by:
Can someone point me to some information on namespace best practices? Questions I have are as follows: 1) Should I use .NET namespaces or URL, URI and URN's? Ie mycompany.mydivision.myapp vs...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.