I would like some advice on how I should, or if I should break up this class. Right now the class is about 4000 lines of code but it seems hard for me to break up the class. The only downfall I see right now is that it can be a little difficult to read.
Anyway, application takes product information from one database and imports it, after doing some conversion, into another database.
I have some classes to interact with the different databases but most of the logic is handled in one class.
Basically the class does this, checks to see if the product already exists, builds sku, get's the product description, attaches a special to the product and adds the product to a category.
So, to me this seems that since it all deals with a product, it all should be in the same class.
I guess I have a few questions. Does this seem like it would all belong in the same class and What are some of the best tips to know what belongs in what class? Does 4000 lines seem to long? Should I use partial classes if it sounds like all this information does belong in one class?
Classes should be designed in such a way that it makes sense to have the members/methods of that class in that class.
If you break up a class purely because it has a lot of code in it, and create a new class then this class will be tightly bound to the original class. Changes made in either class are going to directly effect the other class and could potentially break applications if modifications are made to either class in the future.
My advice would be to look at the class design. Do the methods and properties belong to that class...if you move them out of the class, what effect will that have on the coupling between your classes?
-Frinny
2 1615
I read once somewhere that its a good practice to keep each method within a class to a length of 24 lines of code or less. Of course you cannot always have tiny methods like that, but the principle is good, check if you could optimize and shorten any of your methods.
Secondly check that your code comments are not bloated, too many comments really don't help, on the other side of that coin I do hope, for the sanity of whoever is to maintain that code, that it is indeed commented :)
Check if you can make any of your methods generic, especially frequently used ones. You can then move all those re-usable methods to a common library outside of your class. The code which handles the CRUD operations of the DB is generally the easiest to move out of a class.
Partial classes are a great thing (IMHO). I generally split large classes into partial classes by grouping related methods together. For your class you might group all the methods used to add a product to a category for example.
These are just some general ideas, hope it helps.
Classes should be designed in such a way that it makes sense to have the members/methods of that class in that class.
If you break up a class purely because it has a lot of code in it, and create a new class then this class will be tightly bound to the original class. Changes made in either class are going to directly effect the other class and could potentially break applications if modifications are made to either class in the future.
My advice would be to look at the class design. Do the methods and properties belong to that class...if you move them out of the class, what effect will that have on the coupling between your classes?
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bob Rock |
last post by:
Hello,
in the last few days I've made my first few attempts at creating mixed C++
managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is
visible in those assemblies from a...
|
by: Jack |
last post by:
Hello
I have a library of calculationally intensive classes that is used both by a
GUI based authoring application and by a simpler non-interactive rendering
application. Both of these...
|
by: Aguilar, James |
last post by:
I know that one can define an essentially unlimited number of classes in a
file. And one can declare just as many in a header file. However, the
question I have is, should I?
Suppose that, to...
|
by: Langy |
last post by:
Hello
I'm fairly new to C++ but have programmed several other languages and
found most of c++ fairly easy (so far!).
I've come to a tutorial on classes, could someone please tell me why
you...
|
by: john townsley |
last post by:
do people prefer to design classes for the particular job or for a rangle of
tasks they might encounter now and in the future.
i am doing some simple win32 apps and picking classes is simple, but...
|
by: joye |
last post by:
Hello,
My question is how to use C# to call the existing libraries containing
unmanaged C++ classes directly, but not use C# or managed C++ wrappers
unmanaged C++ classes?
Does anyone know how...
|
by: Edward Diener |
last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ?
I think it must as the compiler, when referencing the assembly, could not
know how the original data is packed otherwise....
|
by: ivan.leben |
last post by:
I want to write a Mesh class using half-edges. This class uses three
other classes: Vertex, HalfEdge and Face. These classes should be
linked properly in the process of building up the mesh by...
|
by: ivan.leben |
last post by:
I am writing this in a new thread to alert that I found a solution to
the problem mentioned here:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8
and to avoid...
|
by: Amu |
last post by:
i have a dll ( template class) ready which is written in
VC++6. But presently i need to inherit its classes into my new C#.net
project.so if there is some better solution with u then please give me...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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...
|
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,...
| |