473,406 Members | 2,208 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.

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 1805
On Dec 7, 5:25 am, "__PPS__" <i-love-s...@yandex.ruwrote:
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.sewrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
On Dec 7, 5:25 am, "__PPS__" <i-love-s...@yandex.ruwrote:
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 RtpConeectionImpl();
then in every function where rtp used there's this line of code:
((RtpConeectionImpl*)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.cpp"
....

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 RtpConeectionImpl();
then in every function where rtp used there's this line of code:
((RtpConeectionImpl*)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 RtpConnectionImpl : public RtpConnection
{
public:
RtpConnectionImpl(some params);

bool do_something();
};
//And class when you use the impl.:
class RtpPlayer
{
public:
RtpPlayer(RtpConnection* 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 MyNewRtpConnectionImpl : public RtpConnection
{
public:
MyNewRtpConnectionImpl(some params);

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

if (use_old_type_connection()) {
rtpcon = new RtpConnectionImpl(some params);
} else {
rtpcon = new MyNewRtpConnectionImpl(another params);
}

RtpPlayer* player = new RtpPlayer(rtpcon);
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
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...
15
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...
4
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...
5
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...
19
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...
9
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 =...
1
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:...
1
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:...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
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...
0
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
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
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.