Topic: Error detection conception
Author: Pavel V. Ivanov <paul@iwep.altai.su>
Date: Mon, 25 Apr 94 17:14:00 +0800 Raw View
The new conception of effective error detection
===============================================
This is dialog between experienced C++ guru and green programmer.
Let's hear what they're talking about:
GREEN: What is a class in OOP ?
GURU: It is somewhat that has all its own data and rules for manipulation.
GREEN: What is inheritance in OOP ?
GURU: Class (object) inherits another class (object) if it has some
resembling features to another class.
GREEN: What is the good OOP program?
GURU: Good OOP program might has multiple kinds, but generally it should
work correctly like other good programs.
GREEN: Please teacher answer more concretly
GURU: In my mind in good OOP program there must be only unclassed function...
GREEN: What do you mean teacher?
GURU: It's main() function boy...
GREEN: It means that all classes should be subclassed from one basic class?
GURU: I knew you're clever guy...
GREEN: Teacher, basic class what is it?
GURU: It's most important matter in OOP programming. Something that incorporate
all of features of problem you dealing with
GREEN: I understand. But teacher I know some examples when I can't join all
classes under one basic class. For instance: my own classes and classes of
iostream. How I can join those classes with mines?
GURU: When I was so greeny as you, I was minded like you too...
GREEN: And...
GURU: Some programmers inherits all classes from so called abstract class,
for example: CUnknown (see OLE 2.0), that can contain only virtual methods.
GREEN: It's so artificial and almost pointless...
GURU: You're clever boy, I knew...
GREEN: You know another way?
GURU: Do you know boy what is error?
GREEN: Oooh, it's head-ache of all programmers
GURU: You're good boy, I knew...
GREEN: I'd inherit all my classes from one basic class for error handling?
GURU: You're righteous!
GREEN: Can you give me small example of that usage?
GURU: See here:
class CError
{
protected:
int m_error;
int m_action;
public:
CError() {m_error=m_action=0;}
~CError() {;}
virtual int ErrorMessage()
{
if(m_error)
cout << "Error occured in unknown class\n";
switch (m_error)
{
case 0 :
break;
case 1 :
cout << "Not enough memory\n";
break;
case 2 :
.....
default:
cout << "Unlisted error" << m_error << "\n";
}
return m_error;
}
};
class CWorker : public CError
{
private:
int *m_pworker
public:
CWorker(int *parray, int size) : CError()
{
m_pworker=new int[size];
if(!m_pworker)
{
m_error=1;
return;
}
}
~CWorker() {delete m_pWorker;}
....
int ErrorMessage()
{
if(m_error)
cout << "Error occured in class CWorker\n";
switch (m_error)
{
case 0 :
break;
case 1 :
cout << "Not enough memory\n";
break;
case 2 :
.....
default:
cout << "Unlisted error" << m_error << "\n";
}
return m_error;
}
};
GREEN: Mmm, now I can trap errors in constructor?
GURU: Naturally! Moreover you can use CError class like CUnknown and more
GREEN: You're great teacher! I'll pray about you before Buddha
GURU: I'm so tired, where is my tin of beer?
GREEN: Teacher! Wait a minute...
GURU: I knew, you're good and pleased boy...
========================================================================
Talking was coded by Paul V. Ivanov
E-mail: paul@iwep.altai.su
25 of April, 1994