473,508 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best practices - how to organize classes

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) InheritorABC - a class that inherits from SuperABC

I can think of two ways of organizing these classes within files:
1) One class per file:
- the file SuperABCClass.py contains the source code for the class
SuperABC
- The file InheritorABCClass.py contains the source code for the class
InheritorABC
- InheritorABC imports SuperABCClass
2) Grouping classes into one .py file:
- the file GroupedABCClasses.py contains the source code for the class
SuperABC and the source code for the class InheritorABC

Seeking reference material that might answer the questions:
When does it make sense to employ the one-class-per-file technique?
When does it make sense to group classes into one .py file?
What are the tradeoffs of using one-class-per-file technique vs the
grouping classes into a single file technique?
Jul 18 '05 #1
1 4065
In article <59*************************@posting.google.com> ,
mi************@yahoo.com (Miranda Evans) wrote:
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) InheritorABC - a class that inherits from SuperABC

I can think of two ways of organizing these classes within files:
1) One class per file:
- the file SuperABCClass.py contains the source code for the class
SuperABC
- The file InheritorABCClass.py contains the source code for the class
InheritorABC
- InheritorABC imports SuperABCClass
2) Grouping classes into one .py file:
- the file GroupedABCClasses.py contains the source code for the class
SuperABC and the source code for the class InheritorABC

Seeking reference material that might answer the questions:
When does it make sense to employ the one-class-per-file technique?
When does it make sense to group classes into one .py file?
What are the tradeoffs of using one-class-per-file technique vs the
grouping classes into a single file technique?


I don't think there is any single correct answer. It's more of a
judgement call.

In general, I'll put more than one class in a single source file only if
they formed a logically self-contained unit of inter-dependant classes.
Kind of like an inner class in C++.

For example, let's say I was building a RedBlackTree class, and I needed
a TreeNode class to store the individual nodes. I would probably put
both classes in one file.

If I needed to define exception classes, they would certainly go in the
same source file as the class which generated those exceptions.
Jul 18 '05 #2

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

Similar topics

1
2268
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...
3
2141
by: wapsiii | last post by:
Looking for better practise! In a large asp.net project, how is it best to organize classes? When should I create a new project for a class? Is it better to have fewer files with all the classes...
10
3416
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...
3
1386
by: Rob | last post by:
Rather new to vb.net... I am wondering if the following is possible and sounds reasonable... Can connection objects and datasets be defined once (at program load) and be available for the life...
9
2018
by: dgiagio | last post by:
Hi, There are dozen very good books out there teaching C language, C standard library, UNIX, Win32 programming of all flavors. Nice... But, I haven't yet found a book that in fact teaches you...
3
3999
by: _DD | last post by:
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...
1
2105
by: AJ | last post by:
Hi all, I am wondering if their are any links out their dealing with best practices when it comes to enterprise web site organization. We are still maintaining classic ASP applications so...
1
1169
by: Will | last post by:
Our shop has 6 .Net developers, most of our work to date has been one developer on a project at a time, occasionally 2 for brief periods of time. We have souce control (SourceGear) and love what...
2
1658
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hi, I have been developing using C# in ASP.Net for about a year now. And have been a programmer for about 10 years. I have learned many different things in .NET, but still when I look at sample...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
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
7382
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...
1
7042
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
7495
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
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.