__PPS__ napisal(a):
Quote:
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();
Quote:
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".
Quote:
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...
Quote:
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