473,698 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class design decision

Hello all,
I was working on someone else's code to implement some classes. The
task seemed to be simple and I was confident that I won't spent alot of
time on that task... But! I've already spent more time to integrade
old working code with new design than it would take me to write it all
from scratch!

so... after having tons of headaches I desided to figure out what's
wrong with the design (or me) and why it's all so complicated.

Here's an example of Rtp Player class. (rtp/rtcp real time data
trnasmition...)
In short RtpPlayer is something that receives data from network, so, it
probably will need to have some kind of connection to the remote end.
Data is encoded, so before playing my rtp player will have to decode
that data. Then to play it (if it's audio) it will have to open audio
device and write data to it.
simplest design is something like:
class rtp_player {
rtp_connection rtp;
data_decoder decoder;
audio_device audio;
public:
...
};
====

Now the way it's badly designed in my case...
rtp_player's has a constructor that takes pointers to interface classes
like this (for sending data):
class data_senderI {
virtual void sendData(const char* data, unsigned int size) = 0;
}
similar shit for decoder, audio device etc.... Not to mention that all
these classes have lot's of other similar shit classes.

So... there's a top level class Media... it has sockets (for
rtp/rtcp)... this class implements data_senderI, then it does new
rtp_player(this , this, this); (it implements other interfaces etc);
I don't know where this kind of garbage design comes from (my guess is
that it's from java world) but it just drives me crazy, I'm getting
lost... There are tens of almost empty classes that do nothing, all of
them have or implement two or three interfaces and it goes on and on.
Result - this construction is unmanagable at all!

Most of the code is constructed in this way... My goal is to convince
managers that a major fix or refactoring is required, how do I convince
them that's not the way to go with all that interfaces user classes and
userInterface classes that came nobody knows from where and designed
nobody knows by who... All other ppl that work on that project are not
good in c++ and they have tons of troubles tracing function call flows
etc...

Any ideas on that? thank you

Dec 7 '06 #1
5 1825
On Dec 7, 5:25 am, "__PPS__" <i-love-s...@yandex.ruw rote:
Most of the code is constructed in this way... My goal is to convince
managers that a major fix or refactoring is required, how do I convince
them that's not the way to go with all that interfaces user classes and
userInterface classes that came nobody knows from where and designed
nobody knows by who... All other ppl that work on that project are not
good in c++ and they have tons of troubles tracing function call flows
etc...

Find an application that can create UML-diagrams from code, create some
diagrams of the existing code, start with class diagrams and if
possible make some iteraction-diagrams or similar of selected parts.
Then sitt down and do a new design the way you want it. Then create
UML-diagrams of your design, one correspondig (if there exist on) for
each of the ones of the old code.

With some luck your design will have fewer classes, shorter call-paths
and fewer dependencies, that would probably result in cleaner diagrams
as well. Show these diagrams to your manages, let them compare your
design and the existing one, explain why your's will be easier to
maintain, extend and so on.

--
Erik Wikström

Dec 7 '06 #2
Now the way it's badly designed in my case...
rtp_player's has a constructor that takes pointers to interface classes
like this (for sending data):
class data_senderI {
virtual void sendData(const char* data, unsigned int size) = 0;
}
similar shit for decoder, audio device etc.... Not to mention that all
these classes have lot's of other similar shit classes.
IMO there's no reason to call this design a shit. It gives you set of
ABCs (abstract base class) that allow you to easily implement different
i.e. data senders and use them all through simple data_senderI class
interface (polymorphism is a great thing). It is normal and proper
technique used with C++.

So... there's a top level class Media... it has sockets (for
rtp/rtcp)... this class implements data_senderI, then it does new
rtp_player(this , this, this); (it implements other interfaces etc);
If I understood correctly, you created class which inherites from many
of library ABCs. It's a bad practice to make such monolith. You should
rather create set of implementations , small and simple classes that
every one of them do just their, strictly constrained, job.

Result - this construction is unmanagable at all!
That's a result of misunderstood of modern C++ usage. Are you skilled
in C++ programming, not C, but C++? I suggest you to get in touch with
C++ FAQ (http://www.parashift.com/c++-faq-lite/) and "C++ Coding
Standards: 101 Rules, Guidelines, and Best Practices" of Herb Sutter
and Andrei Alexandrescu
(http://www.amazon.com/exec/obidos/AS.../modecdesi-20), if
you aren't familiar with them already.

Most of the code is constructed in this way... My goal is to convince
managers that a major fix or refactoring is required, how do I convince
them that's not the way to go with all that interfaces user classes and
userInterface classes that came nobody knows from where and designed
nobody knows by who...
Do you like your job? If yes, than you should not even try to do this!
Just sit, learn and improve your C++ skills. It is you this time, who
have to adapt to the situation.

The same advice goes to other people working on this projects that "are
not good in c++".

I wish you good luck!

Dec 7 '06 #3
I just installed Doxygen on my machine this week along with GraphViz
which Doxygen uses to make lots of pretty graphs of your code. Highly
recommended and free!

Tony

<er****@student .chalmers.sewro te in message
news:11******** **************@ 80g2000cwy.goog legroups.com...
On Dec 7, 5:25 am, "__PPS__" <i-love-s...@yandex.ruw rote:
Most of the code is constructed in this way... My goal is to convince
managers that a major fix or refactoring is required, how do I convince
them that's not the way to go with all that interfaces user classes and
userInterface classes that came nobody knows from where and designed
nobody knows by who... All other ppl that work on that project are not
good in c++ and they have tons of troubles tracing function call flows
etc...

Find an application that can create UML-diagrams from code, create some
diagrams of the existing code, start with class diagrams and if
possible make some iteraction-diagrams or similar of selected parts.
Then sitt down and do a new design the way you want it. Then create
UML-diagrams of your design, one correspondig (if there exist on) for
each of the ones of the old code.

With some luck your design will have fewer classes, shorter call-paths
and fewer dependencies, that would probably result in cleaner diagrams
as well. Show these diagrams to your manages, let them compare your
design and the existing one, explain why your's will be easier to
maintain, extend and so on.

--
Erik Wikström
Dec 7 '06 #4
Ok, data_senderI is a good choice for abstract interface, but not a
good example for my case. There are many classes that are used ony in
one place: abstract RtpConnection class is used only in one place like
this:
someclass {RtpConnection *rtp; }
then somewhere: rtp = new RtpConeectionIm pl();
then in every function where rtp used there's this line of code:
((RtpConeection Impl*)rtp) -do_some_shit();
Nice!
That's a result of misunderstood of modern C++ usage. Are you skilled
in C++ programming, not C, but C++? I suggest you to get in touch with
C++ FAQ (http://www.parashift.com/c++-faq-lite/) and "C++ Coding
Standards: 101 Rules, Guidelines, and Best Practices" of Herb Sutter
and Andrei Alexandrescu
(http://www.amazon.com/exec/obidos/AS.../modecdesi-20), if
you aren't familiar with them already.

Never knew C. Started from c++. I've read these books a few years ago
(not completely, though). Sometimes I read Sutter's gotw.ca, I love c++
faq.

Do you like your job? If yes, than you should not even try to do this!
Just sit, learn and improve your C++ skills. It is you this time, who
have to adapt to the situation.
I personally beleive that I'm good enough in c++. Some ppl at my work
say so (very good) :)
Well, I said to the managers that somebody wrote interfaces so that I
need to implement all of them. I said that I can as well design code
myself and I don't need anybody do useless work (designing empty
interfaces). They agreed with me, now I do it all on my own.
>
The same advice goes to other people working on this projects that "are
not good in c++".
These ppl aren't really working with me. They are direct emplyees, I'm
a consultant. I help them find/fix errors, teaching them c++ is not my
responsibility (I don't want to loose my job if they become good
enough, just joking). Anyways, they don't code anything - I end up
doing everything anyways.

Tony wrote:
I just installed Doxygen on my machine this week along with GraphViz
which Doxygen uses to make lots of pretty graphs of your code. Highly
recommended and free!

Yes!!! That's true... I wanted to do it this way. In big projects I do
it this way... BUT dyoxygen choked on this code. Some geniuses designed
new way of inheritance:
..h: ===
namespace voip{
class Service {
#include "../serice_common.h "
...
}

..cpp ===
using namespace voip;
#include "../serice_common.c pp"
....

So, there are tens of different services and all of them are written
this way, so that at the end dyoxygen cannot resolve this cpp files and
cannot draw me anything...

Dec 7 '06 #5
__PPS__ napisal(a):
Ok, data_senderI is a good choice for abstract interface, but not a
good example for my case. There are many classes that are used ony in
one place: abstract RtpConnection class is used only in one place like
this:
someclass {RtpConnection *rtp; }
then somewhere: rtp = new RtpConeectionIm pl();
then in every function where rtp used there's this line of code:
((RtpConeection Impl*)rtp) -do_some_shit();
Nice!
Wrong!

Assume RtpConnection is abstract base class:
class RtpConnection
{
public:
virtual bool do_something() = 0;
};
//You have implementation like this:
class RtpConnectionIm pl : public RtpConnection
{
public:
RtpConnectionIm pl(some params);

bool do_something();
};
//And class when you use the impl.:
class RtpPlayer
{
public:
RtpPlayer(RtpCo nnection* rtpcon) : mRtpCon(rtpcon) {}

void play();
private:
RtpConnection* mRtpCon;
};

void RtpPlayer::play ()
{
mRtpCon->do_something() ; // no indirection needed
}
/*
The RtpPlayer class doesn't know anything about implementation. It uses
only ABC defined interface, so it is independent of any further
RtpConnection implementations . This is VERY important in case of code
reusability. Remember, that somewhen in future someone else may be
using RtpPlayer but with another connection implementation. In that
case he doesn't have to change anything - just create another
RtpConnection implementation. That's why use of ABCs is a good approach
in OOP. I.e.:
*/
class MyNewRtpConnect ionImpl : public RtpConnection
{
public:
MyNewRtpConnect ionImpl(some params);

bool do_something(); // probably something else then before
};
//And somewhere in the code:
RtpConnection* rtpcon = 0;

if (use_old_type_c onnection()) {
rtpcon = new RtpConnectionIm pl(some params);
} else {
rtpcon = new MyNewRtpConnect ionImpl(another params);
}

RtpPlayer* player = new RtpPlayer(rtpco n);
player->play();

Never knew C. Started from c++. I've read these books a few years ago
(not completely, though). Sometimes I read Sutter's gotw.ca, I love c++
faq.
Strange love, if you doesn't use advices they provide... i.e.
http://www.parashift.com/c++-faq-lite/abcs.html, rule no 36 in "C++
Coding Standards" - "Prefer providing abstract interfaces".

I personally beleive that I'm good enough in c++. Some ppl at my work
say so (very good) :)
Are they better than you? If they aren't, there is no reason to be
happy... Really...

Well, I said to the managers that somebody wrote interfaces so that I
need to implement all of them. I said that I can as well design code
myself and I don't need anybody do useless work (designing empty
interfaces). They agreed with me, now I do it all on my own.
Are your managers skilled in C++ or even OO programming? Can they
knowingly decide if you are right?
I have a strong feelling, that you graduated recently (maybe some
university), because your arrogant treatment of somebody's job (a good
job), shit-filled comments, blaming of good programming practices is so
relevant. Calm down, get a little more modesty, and try to find out
what was those solutions made for.

greetz

Dec 8 '06 #6

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

Similar topics

50
6349
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong def foo(self, data): self.attr1=data self.attr2.append(data) The initialization of attr1 is obviously OK, all instances of Father redefine it in the method foo. But the initialization of attr2 is wrong
15
9065
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for the purpose of learning to work with C++. It therefore makes some sense for me to give the situation the amount of consideration presented below. To be quite honest, I'm amazed at the amount there is to say about such a seemingly simple...
4
2878
by: Christian Christmann | last post by:
Hi, I need an STL list and was thinking of putting the list in wrapper class. The reason for my decision is that you can much better perform consistency checks. For instance, I need a function to append a list to another. Using a wrapper class I could do something like:
5
1990
by: Dave Johnson | last post by:
Working on Asp.net with access database backend,a serious Question in the Class design phase, for accessing the database; Which is Better to make a Connection Class that handles all the ADO Connections for all the other Objects, OR Just make a Connection Module to handle the Database Access,
19
1645
by: Michael | last post by:
Hi, typedef std::vector<Vehicle* VehicleList; Vehicle is a UDT, or a class. Why is Vehicle* not just Vehicle in < >. Which one is better and why? If you could explain it by laying out some codes, it would be highly appreciated! Thanks in advance, Michael
9
2356
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice = CDec(txbInv.Text) Wage = CDec(txbTotWage.Text)
1
3051
by: Ezmeralda | last post by:
Hello, I need to an TCP/IP Interface for communication with an embedded device. Since I have two different design ideas in mind, I am wondering whether you could give me some hints to decide: Requirements: - Interface should be used for company internal purposes/software but
1
3750
by: Ezmeralda | last post by:
Hello, I need to an TCP/IP Interface for communication with an embedded device. Since I have two different design ideas in mind, I am wondering whether you could give me some hints to decide: Requirements: - Interface should be used for company internal purposes/software but
6
8156
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a situation where I am implementing base class functions by including a pointer to subclass member in base class. Reason being functionality is common for subclasses but the members are common within subclass only (static member of subclass) but...
0
9166
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.